#!/usr/bin/env python import os import glob import sys import subprocess import traceback import hashlib import urllib import urllib2 ZINT = 'zint' ZINT_RSS_EXPANDED_CODE = 31 ZINT_BINARY = "zint" # If available in PATH POSTSCRIPT = 'postscript' TEST_FILE = "../../../src/com/google/zxing/oned/rss/RSSExpandedBlackBox3TestCase.java" def check_zint(): try: subprocess.Popen("zint", stdout=subprocess.PIPE, stderr=subprocess.PIPE) except: print >> sys.stderr, "zint not installed. Go to http://www.zint.org.uk/ and install it" return False return True def check_postscript(): return True GENERATORS = [] if check_zint(): GENERATORS.append(ZINT) if check_postscript(): GENERATORS.append(POSTSCRIPT) def generate_image_zint(image_filename, barcode): braces_barcode = barcode.replace("(","[").replace(")","]") os.system('%s -o %s -b %s -d "%s"' % (ZINT_BINARY, image_filename, ZINT_RSS_EXPANDED_CODE, braces_barcode.replace('"','\\"'))) def generate_image_postscript(image_filename, barcode): hashname = "cache/%s.png" % hashlib.new("md5", barcode).hexdigest() # If it exists in the cache, don't download it if os.path.exists(hashname): content = open(hashname).read() open(image_filename,'w').write(content) return # We tried use the Python, Perl and LaTeX bindings without success :-( baseurl = "http://www.terryburton.co.uk/barcodewriter/generator/" encoded = urllib.urlencode({ "encoder" : "rssexpanded", "data" : barcode, "options" : "", "translate_x" : "50", "translate_y" : "50", "scale_x" : "2", "scale_y" : "2", "rotate" : "0", "submit" : "Make Barcode" }) web_urlobject = urllib2.urlopen(baseurl, data = encoded) web_content = web_urlobject.read() png_url = web_content.split('">PNG')[0].split('