Unicode and Python

If you want to get a great introduction to Unicode in Python, watch (not just read, watch) Ned Batchelder’s presentation, Pragmatic Unicode. The most important thing I took away from it was to decode to Unicode string as soon as you have any input (file, network, etc.) and to encode to binary string as late as possible to give back to user, system, etc. Another thing is to know what encoding has been used so you can decode and encode back as necessary. These two are applicable to all programming, whether it’s in Python or some other language.

Some more things to remember:

  • “\u2119″ is a Unicode string containing one code point. Use a lowercase \u with four hex digits. Use uppercase \U with more-than-four (usually eight) hex digits in the same code point.
  • “\xe2″ is a binary string containing one byte.
  • Always try to use UTF-8.

Good Luck, Ubuntu

I have been a huge fan, supporter, and promoter of Ubuntu since about 2006. All the things that attracted me initially were: gratis, free/libre, community, just one CD to install. As I used it more I liked the technical merits as well, things such as timely releases, hardware support, server version, application availability, and LTS. I used it at home and work whenever I could. But things were not always perfect. Things popped up here and there that made Canonical’s direction for Ubuntu more important than the community’s. Things such as CLA, proprietary Landscape, Launchpad, bzr, Unity (initial releases; I love it now), Upstart, Amazon-in-Dash, etc. There was a visible Not Invented Here (NIH) syndrome in Ubuntu, which was good to some extent but then became overwhelmingly powerful. In an effort to control all the things they cared about, Canonical started deviating from the wider Linux ecosystem.

Upstart was a great idea and executed well enough that it was included in other distributions. But then Red Hat’s NIH kicked in and they created an alternative, systemd, and convinced other distributions to adopt it. Debian and Ubuntu are the standouts in not having embraced systemd yet. I have used systemd and as a user I loved it. It makes it easier to manage my services without getting in my way. I don’t know how I would like it in a sysadmin role but I don’t think it’ll be awful. So now if the wider Linux community accepts systemd then why ignore it?

Traditions are important but innovation and change are even more important. Canonical is driving that change in Ubuntu, especially with Mir. But it’s such as ill-advised change. When Wayland has been the community darling for a while, and Ubuntu kept saying they would replace X with it, why go the Mir route? Control; that’s what Canonical wants. It’ll allow them to compete with Google and Apple and make free software available to everyone in every form factor. Canonical is essentially changing its target audience from everyone (users, software developers, sysadmins, enterprises, etc.) to some (users, carriers, hardware manufacturers, enterprises, application developers, etc.). They don’t want Ubuntu developers anymore, they want developers building “apps” for Ubuntu. Which is fine if that’s their goal but they should realize that a lot of their original community members will leave as they don’t fit in anymore. But with Mir the real fear is that a lot of good work done recently with open source graphics drivers will be outdone by manufacturers targeting Mir to the detriment of the rest of the Linux world.

If all the secrecy around Ubuntu phone, Mir, QT-based Unity, etc. was because Canonical feared competition would take their ideas and build products faster than they could, they have missed the bazaar of free software where ideas are presented, discussed, and developed in collaboration for the benefit of all. So what if someone else takes your idea and builds a proprietary product? Our (your) goal is to create a free software product.

Unless you have the financial resources of Apple, Google, and Microsoft you can’t build an OS end-to-end on your own. You need a volunteer community to do that. Red Hat and SUSE understand that and try to build better community relations. Yes, they are not perfect and can be heavy handed when their goals are at stake but they haven’t discarded the community like Canonical has. If what Elizabeth Krumbach says has any weight in it (and I would agree it does), then the Ubuntu community will be less involved (if any) with code development as time goes by, and will be relegated to QA, documentation, support, etc. So the community will support whatever the Canonical cathedral code-dumps on the world without any input on the direction of the code.

Of course, Canonical and Shuttleworth have spent a lot of time, energy, and money to make Ubuntu what it is today. They do need to make money to continue Ubuntu. But at what cost? Is world dominance (with free software) a worthier goal than free software? Is free software meant to be dumped on users in “tada” moments? Free software performs two functions: gives rights to users as well as promotes collaboration. If Canonical doesn’t want collaboration on Ubuntu from a wider community then it’s their eventual loss. They’ll be hard pressed to continue their growth without a significant contribution from a diverse community. Red Hat is now a billion-dollar company but it also can’t create a complete OS and all its other offerings on its own. You need to be the size of Google and Apple to pull that off. Given this situation, can Canonical afford to disenfranchise its most ardent supporters?

Many like me will move away to other distributions. Debian is the obvious choice. But I would like people to give Fedora a chance as well. It’s not as easy as Ubuntu or stable as Debian but it strikes a good balance between innovation and breaking things. Once you get used to Fedora’s quirks and cadence you’ll find a truly free OS that makes community an essential part of its existence. Meanwhile, I wish Ubuntu good luck in Canonical’s endeavors. I hope by Ubuntu 14.04 we’ll see Canonical reach its goals and prove us all wrong.

Edit:

Do I care about the end product or the process of creating the product? If you’re a free software enthusiast you’ll most likely want to be involved in the process, from beginning to end. Yes, the end product is important but so is the process. And you can’t build a product if you don’t have enthusiasts willing to step in and do the hard work. Well, you can, but you’ll need huge financial resources to do so. Does Canonical have the money and willingness to take Ubuntu forward on its own?

Reaction to Ubuntu Phone Announcement

My first reaction is a very positive one. I welcome a new perspective to the mobile market. It’s a cool concept to have the same underlying OS on your phone, desktop, and server. The actual product is about a year from being in consumer hands. But the announcement now means that developers can create apps, handset manufacturers can build phones, carriers can make deals to bring them on their networks, etc. It’s good to have this discussion going.

I’m disappointed with all the negativity on reddit surrounding the announcement. Yes, the project’s not done yet. It’s not ready to ship. It might not be successful. It may not get enough compelling apps. Why be negative? It’s a new year, a new product, a new beginning. Let’s voice our support now. If it fails, it fails, and we can move on to another project. But let’s give this an honest effort and aim for success.

Ubuntu Phone, I’ll vocally support your development starting today. I may not be able to contribute apps but I may buy you when you’re released.

iPhone: Turn Off Phone Network and Data But Keep WiFi On

When you are traveling to a place where your carrier would charge exorbitant prices for data, text, or minutes you may want to disable all phone, text, and data on your iPhone. But you also want to keep Wi-Fi working. It’s a really simple, two-step process, all under Settings.

  1. Turn on Airplane Mode. This will turn off phone, data, text, and Wi-Fi.
  2. Turn on Wi-Fi. Your phone, data, and text services will remain disabled. But you can still iMessage when you’re connected to Wi-Fi.

Convert Windows Server 2012 Datacenter Eval to Datacenter

If you were lucky enough to have used Windows Server 2012 Datacenter eval edition you might have a need to convert it to a regular release. It can easily be done using PowerShell.

Step 1 is to figure out what edition you are currently running.

DISM /online /Get-CurrentEdition

Step 2 is to enter the license key for the full edition. You’ll be asked to reboot the server so say yes.

DISM /online /Set-Edition:ServerDatacenter /ProductKey:ABCD-EFGH-IJKL-MNOP-QRST /AcceptEula

That’s all!

Create deb Package in Ubuntu (Very Brief Introduction)

This is a very brief and basic introduction to creating a deb package. It’s more of a log /history of commands I ran (while learning this myself) and their output. Special thanks to How To Create A .DEB Package [Ubuntu / Debian] for serving as the base I used to build this post. Log in to your Ubuntu machine and open a terminal. Then run the following commands.

cg@codeghar:~$ mkdir custom-package

cg@codeghar:~$ cd custom-package/

cg@codeghar:~/custom-package$ pwd

/home/cg/custom-package

cg@codeghar:~/custom-package$ mkdir credner-1.0

cg@codeghar:~/custom-package$ cd ~/source/

cg@codeghar:~/source$ ls

credner-1.0.tar.gz  credner.py

cg@codeghar:~/source$ vim credner.py

#!/usr/bin/env python3
print ("Hello World!")

cg@codeghar:~/source$ cp credner-1.0.tar.gz ~/custom-package/

cg@codeghar:~/source$ cd -

/home/cg/custom-package

cg@codeghar:~/custom-package$ ls

credner-1.0  credner-1.0.tar.gz

cg@codeghar:~/custom-package$ sudo aptitude install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot xutils lintian pbuilder

Note: All these packages will be installed as required.

cg@codeghar:~/custom-package$ ls

credner-1.0  credner-1.0.tar.gz

cg@codeghar:~/custom-package$ cd credner-1.0/

cg@codeghar:~/custom-package/credner-1.0$ ls

cg@codeghar:~/custom-package/credner-1.0$ dh_make -e credner@example.com -f ../credner-1.0.tar.gz

Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch?
 [s/i/m/l/k/n] s

Maintainer name  : codeghar
Email-Address    : credner@example.com
Date             : Wed, 14 Nov 2012 16:02:15 -0800
Package Name     : credner
Version          : 1.0
License          : blank
Type of Package  : Single
Hit  to confirm:
Currently there is no top level Makefile. This may require additional tuning.
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the credner Makefiles install into $DESTDIR and not in / .

cg@codeghar:~/custom-package/credner-1.0$ ls

debian

cg@codeghar:~/custom-package/credner-1.0$ cd debian/

cg@codeghar:~/custom-package/credner-1.0/debian$ ls

changelog          credner.default.ex   emacsen-startup.ex  menu.ex      README.Debian
compat             credner.doc-base.EX  init.d.ex           postinst.ex  README.source
control            docs                 manpage.1.ex        postrm.ex    rules
copyright          emacsen-install.ex   manpage.sgml.ex     preinst.ex   source
credner.cron.d.ex  emacsen-remove.ex    manpage.xml.ex      prerm.ex     watch.ex

cg@codeghar:~/custom-package/credner-1.0/debian$ vim control

Source: credner
Section: unknown
Priority: extra
Maintainer: codeghar 
Build-Depends: debhelper (>= 8.0.0)
Standards-Version: 3.9.2
Homepage: 
#Vcs-Git: git://git.debian.org/collab-maint/credner.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/credner.git;a=summary

Package: credner
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: First test deb package
 This is my first deb package attempt

cg@codeghar:~/custom-package/credner-1.0/debian$ vim copyright

Format: http://dep.debian.net/deps/dep5
Upstream-Name: credner
Source: 

Files: *
Copyright: 2012 codeghar 
License: GPL-2+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see 
 .
 On Debian systems, the complete text of the GNU General
 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2012 codeghar 
License: GPL-2+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see 
 .
 On Debian systems, the complete text of the GNU General
 Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.

cg@codeghar:~/custom-package/credner-1.0/debian$ vim changelog

credner (1.0-1) unstable; urgency=low

  * Initial release (Closes: #nnnn)  

 -- codeghar   Wed, 14 Nov 2012 16:02:15 -0800

cg@codeghar:~/custom-package/credner-1.0/debian$ cd ..

cg@codeghar:~/custom-package/credner-1.0$ dpkg-buildpackage -us -uc -rfakeroot

dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor): -D_FORTIFY_SOURCE=2
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions -Wl,-z,relro
dpkg-buildpackage: source package credner
dpkg-buildpackage: source version 1.0-1
dpkg-buildpackage: source changed by codeghar 
dpkg-buildpackage: host architecture amd64
 dpkg-source --before-build credner-1.0
 fakeroot debian/rules clean
dh clean
   dh_testdir
   dh_auto_clean
   dh_clean
 dpkg-source -b credner-1.0
dpkg-source: info: using source format `3.0 (quilt)'
dpkg-source: info: building credner using existing ./credner_1.0.orig.tar.gz
dpkg-source: warning: ignoring deletion of file credner.py
dpkg-source: info: building credner in credner_1.0-1.debian.tar.gz
dpkg-source: info: building credner in credner_1.0-1.dsc
 debian/rules build
dh build
   dh_testdir
   dh_auto_configure
   dh_auto_build
   dh_auto_test
 fakeroot debian/rules binary
dh binary
   dh_testroot
   dh_prep
   dh_installdirs
   dh_auto_install
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_installexamples
   dh_installman
   dh_installcatalogs
   dh_installcron
   dh_installdebconf
   dh_installemacsen
   dh_installifupdown
   dh_installinfo
   dh_installinit
   dh_installmenu
   dh_installmime
   dh_installmodules
   dh_installlogcheck
   dh_installlogrotate
   dh_installpam
   dh_installppp
   dh_installudev
   dh_installwm
   dh_installxfonts
   dh_installgsettings
   dh_bugfiles
   dh_ucf
   dh_lintian
   dh_gconf
   dh_icons
   dh_perl
   dh_usrlocal
   dh_link
   dh_compress
   dh_fixperms
   dh_strip
   dh_makeshlibs
   dh_shlibdeps
   dh_installdeb
   dh_gencontrol
dpkg-gencontrol: warning: Depends field of package credner: unknown substitution variable ${shlibs:Depends}
   dh_md5sums
   dh_builddeb
dpkg-deb: building package `credner' in `../credner_1.0-1_amd64.deb'.
 dpkg-genchanges  >../credner_1.0-1_amd64.changes
dpkg-genchanges: including full source code in upload
 dpkg-source --after-build credner-1.0
dpkg-buildpackage: full upload (original source is included)

cg@codeghar:~/custom-package/credner-1.0$ ls

debian

cg@codeghar:~/custom-package/credner-1.0$ cd ..

cg@codeghar:~/custom-package$ ls

credner-1.0                  credner_1.0-1.debian.tar.gz  credner-1.0.tar.gz
credner_1.0-1_amd64.changes  credner_1.0-1.dsc
credner_1.0-1_amd64.deb      credner_1.0.orig.tar.gz

cg@codeghar:~/custom-package$ sudo dpkg --install credner_1.0-1_amd64.deb

[sudo] password for codeghar:
Selecting previously unselected package credner.
(Reading database ... 84043 files and directories currently installed.)
Unpacking credner (from credner_1.0-1_amd64.deb) ...
Setting up credner (1.0-1) ...

cg@codeghar:~/custom-package$ dpkg --list credner

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version           Description
+++-=================-=================-==================================================
ii  credner           1.0-1             First test deb package

cg@codeghar:~/custom-package$ dpkg --listfiles credner

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/credner
/usr/share/doc/credner/copyright
/usr/share/doc/credner/changelog.Debian.gz
/usr/share/doc/credner/README.Debian

cg@codeghar:~/custom-package$ sudo dpkg --purge credner

(Reading database ... 84047 files and directories currently installed.)
Removing credner ...

cg@codeghar:~/custom-package$ dpkg --list credner

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name              Version           Description
+++-=================-=================-==================================================
un  credner                       (no description available)

From this tutorial you can learn the very basics of how to create a deb package. In our example package credner.py was not installed, and that’s alright. Our main purpose was to show the building blocks for now. We also installed a whole bunch of packages we might not have needed for this example. That’s ok, too, because as we continue our learning process we might need them.

My next goal is to create a deb package from a proper Python script. Stay tuned.

Follow

Get every new post delivered to your Inbox.

Join 26 other followers