Skip to content

Instantly share code, notes, and snippets.

@cgibson
cgibson / asynctest.py
Created November 3, 2012 08:46
Example extension to the threading.Thread class to catch return values.
import threading
import time
from functools import wraps
class AsyncReturn (threading.Thread):
def run(self):
# Give us a default value in case we time out our join() call
# later on
@cgibson
cgibson / fabric_wrapper_test.py
Created October 21, 2012 02:28
Run fabric commands in unittests using a function wrapper
import unittest
from fabric.api import env, execute, run, task
from functools import wraps
#
# Fabric command wrapper. Essentially, this surrounds any specified command
# call with the execute() function. Adding this function decoration to unit-
# tests allows us to avoid using execute() functions within our tests.
#
@cgibson
cgibson / duco_send_text.py
Created May 27, 2011 18:59
Duco - Send Text After Render
def send_message(number, message, username, password):
voice = Voice()
voice.login(username, password)
voice.send_sms(number, message)
@cgibson
cgibson / run_duco_render_process.py
Created May 27, 2011 18:55
Run Duco Render Process
t0 = time.time()
p = subprocess.Popen([cmdStr], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
t1 = time.time()
t = t1 - t0
os.symlink("%s/%s" % (job_dir, imgFile), "%s/%s.tga" % (images_folder, job_name))
stdout = p.stdout
stderr = p.stderr
@cgibson
cgibson / get_next_job.py
Created May 27, 2011 18:53
Retrieve next job from ducovar["JOBS"]
def get_next_job(jobs_folder):
dirList = os.listdir(jobs_folder)
for fname in dirList:
if (os.path.isfile(jobs_folder + '/' + fname)) and ("run" in fname[-3:]):
return fname[:-4]
return ""
@cgibson
cgibson / pid.py
Created May 27, 2011 18:47
PID lock/release
ducovar = dict()
pid = str(os.getpid())
def pid_exists():
return os.path.isfile(ducovar["PID_FILE"])
def write_pid():
if len(ducovar["PID_FILE"]) == 0:
print "Error: invalid pid file [%s]" % ducovar["PID_FILE"]
@cgibson
cgibson / propload.py
Created May 27, 2011 18:26
Property loading function in python
# Prop file load
# Based off of http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch34s04.html
def load_prop(filename):
try:
f = file( filename, 'rU' )
except:
print "Error: no such property file %s" % filename
sys.exit()
d = dict()
for propline in f: