Tyrel's Blog

Code, Flying, Tech, Automation

Jan 13, 2012

You can un-expire a GPG key.

Today we had a problem at work on a system. Without getting into too much detail as to give away secrets behind the verbal NDA I am behind, I will just say that it had to do with a GPG public key of mine that was expired on a dev machine, accidentally propagating during install to a production machine. This key had a sub key as well, so figuring out this was tricky.

To start, you can list your gpg keys like so:

$ gpg --list-keys

This will list keys such as

pub 4096R/01A53981 2011-11-09 [expires: 2016-11-07]
uid Tyrel Anthony Souza (Five year key for email.)
sub 4096R/C482F56D 2011-11-09 [expires: 2016-11-07]

To make this not expire, (same steps to change expiration date to another time), you must first edit the key

$ gpg --edit-key 01A53981

You will then see a gpg prompt gpg>

Type "expire" in and you will be prompted for how long to change it to

Changing expiration time for the primary key.
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years

You are then done setting the expiration on the primary key, if you have sub key, doing this is as easy as typing key 1 and repeating the expiration step.

To finish and wrap things up, type save and you are done.

 · · ·  linux  gpg

Jan 05, 2012

Custom Django URLField

For work I had to write a custom url model field. This model field when setting up accepts a default protocol, and a list of other protocols.

When checking the protocol, the url is split by "://". If the split has one or two parts, then the url is validly formed.

In the event of a single element split, there is no protocol specified. When there is no protocol, the url is prepended with the default protocol specified. If there is a protocol, it is checked to make sure it exists in a union of the default protocol and other protocols. If it is not, a ValidationError is raised letting the user know that the protocol is not accepted.

This can all be found at On my github [deadlink].

I have a couple ways I could have done this better and probably will. Improvements would be just one parameter called parameters in which it is checked if there is at least one element. Passing this, when there is no protocol specified, the first element is the default one.

This would be a little cleaner.

this example would allow for http, https, ssh, spdy and mailto, anything else would error out.

facebook_page = URLField(default_protocol="http", protocols=["https","ssh","spdy","mailto"])

The way I could improve this would be

facebook_page = URLField(protocols=["https","https","ssh","spdy","mailto"])
 · · ·  python  django

Dec 21, 2011

Python Progress Bar

I was looking for a nice progress bar today at work to show progress rather than just printing "Waiting 30 seconds…" and having the script do nothing, I wanted to have a progress bar show.

I found a progress bar from Corey Goldberg

I did make a couple changes, and have uploaded my changes to my GitHub account.

newPythonProgressBar [deadlink]

To use this progressbar, it is very easy.

# To Setup
from progress_bar import ProgressBar
import sys
import time
def updateBar(step):
    p.update_time(step)
    sys.stdout.write("%s\r" % p)
    sys.stdout.flush()
#
# to call
#
wait_time = 100 # seconds
p = ProgressBar(wait_time)
p.empty_char = "."
p.unit = "^"
for step in range(wait_time+1):
    updateBar(step)
    time.sleep(1)

It will look like this when you use it

[###...............7%..................] 7^/100^

 · · ·  Python
← Previous Page 7 of 7