Tuesday, June 7, 2016

Make test pypi the default pip installer

It's possible to make the testpypi index the default for pip, but still retrieve any dependencies not on testpypi from the production repo. You just need a pip.conf like this:
$ mkdir ~/.pip
$ cat .pip/pip.conf 
index-url = https://testpypi.python.org/simple
extra-index-url = https://pypi.python.org/simple

Sunday, May 22, 2016

Lowe's OC821 Iris Outdoor Video Camera

Some quick links to help others find information about using the Lowe's OC821 outdoor video camera without paying for the overpriced Lowe's security monitoring system.

Honestly though it looks like this camera was designed to be used via the API from the Iris hub, which I don't want to pay for. I'm going to replace it with something (Dropcam or similar) that doesn't require ongoing fees and has a better phone app.

Wednesday, May 18, 2016

Bash default value environment variable that can be overridden

Often in bash scripts I want to have a constant that is overridable. It's something I expect people to want to change but isn't worth creating commandline options for.

Here's how to do it:

: ${OVERRIDABLE:="thedefault"}

And it works like this:
$ bash ./temp.sh 
$ OVERRIDABLE="overridden" bash ./temp.sh 

Friday, May 13, 2016

launchd ThrottleInterval

Apple's documentation of the launchd options leave a lot to be desired.  It leaves out important details and is fairly ambiguous about lots of things. Various people are trying to document it themselves, so here's another addition for ThrottleInterval.

The launchd.plist man page says:

ThrottleInterval This key lets one override the default throttling policy imposed on jobs by launchd. The value is in seconds, and by default, jobs will not be spawned more than once every 10 seconds. The principle behind this is that jobs should linger around just in case they are needed again in the near future. This not only reduces the latency of responses, but it encourages developers to amortize the cost of program invocation.

What it really means is this:

By default jobs are expected to run for at least 10 seconds. If they run for less than 10 seconds, they will be respawned "10 - runtime" seconds after they die. Exit code is ignored, all that matters is runtime. If a job runs for more than 10 seconds then exits, it will be respawned immediately (assuming all other restart conditions are met).

So instead of just throttling how often a service gets restarted, ThrottleInterval also implies minimum runtime. Which is surprising to more than just me.

You'll see a message like this in the logs if the service dies inside the ThrottleInterval:
com.apple.xpc.launchd[1] (com.apple.mdworker.shared.03000000-0000-0000-0000-000000000000): Service only ran for 3 seconds. Pushing respawn out by 7 seconds.

Thursday, May 12, 2016

Python check compilation flags: CFLAGS

Here's a handy command to print the CFLAGS that python was compiled with:
$ python-config --cflags
-I/usr/local/Library/Taps/homebrew/homebrew-core/PYTHON_ENV/include/python2.7 -I/usr/local/Library/Taps/homebrew/homebrew-core/PYTHON_ENV/include/python2.7 -fno-strict-aliasing -fno-common -dynamic -march=core2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes

Wednesday, May 11, 2016

pip and distutils setup.py cheatsheet

Download source for version 2.1:
pip download somepackage==2.1
Make a source distribution and stick it in another directory:
python setup.py sdist --dist-dir="${HOME}/dist-out"
Build wheels:
python setup.py bdist_wheel
you'll find them under dist/

Friday, May 6, 2016

Building a debian package for PPA distribution

Before you start packaging for PPA you should know two things:
  1. Packages must be built from source only. PPAs do not accept built .debs. Only source tarballs are allowed for security and opensource licensing reasons.
  2. All dependencies must be satisfied from the ubuntu repo or other PPAs. No internet access for build due to security and build repeatability.
Those two things basically made it impossible for me to use a PPA, but here's the notes anyway.
  1. Create a launchpad account.
  2. From your account page you can click "Create a new PPA".
  3. Add your gpg key to your account as explained here. Use this to get the fingerprint:
  4. gpg --fingerprint
  5. Update your debian/changelog file for the new version by running:
  6. dch -i
  7. Build your source package. Personally I found creating a Dockerfile was a nice way to do it that avoided having to install all the build dependencies on my own system (although this may not be worth it if you are just going to build the source package). Pbuilder is also an alternative. Inside your Dockerfile you will run this to get an unsigned .changes and .dsc:
  8. dpkg-buildpackage -S
  9. Sign your .changes with debsign. You only need to specify -e here if your keyname is different to the package maintainer email in your control file.
  10. debsign -e myemail@mydomain mypackage_3.1.0-2_amd64.changes
  11. Upload to the PPA:
  12. dput ppa:myusername/testppa mypackage_3.1.0-2_amd64.changes