def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "hi:q:lt:v", ["help", "import=", "id=", "list", "test", "verbose", "limit=", "start="]) except getopt.error, msg: raise Usage(msg) #print(opts) #print(args) action = None store_file = None # option processing for option, value in opts: if option == "-v": verbose = True if option in ("-h", "--help"): raise Usage(help_message) if option in ("-i", "--import"): store_file = value print('store file: {0}'.format(store_file)) action = 'import' elif option in ("-l", "--list"): action = 'list' elif option in ("-t", "--test"): action = 'test' filename = value elif option in ("-q", "--id"): action = 'get' id = value else: pass print('action: {}'.format(action)) if (action == 'list'): imsto = ImSto() gallery = imsto.browse() for img in gallery['items']: #print(img) print("{0[filename]}\t{0[length]:8,d}".format(img)) return 0 elif (action == 'get') and id is not None: imsto = ImSto() if not imsto.getFs().exists(id): print ('not found') return 1 gf = imsto.get(id) #print(gf) print ("found: {0.name}\t{0.length}".format(gf)) return 0 elif (action == 'test'): print('filename: %r' % filename) fp = open(filename, 'rb') h = fp.read(32) print(getImageType(h)) return 0
def manage(environ, start_response): path_info = environ.get('PATH_INFO', '') man_regex = r'^/([A-Za-z]+)/(env|Gallery|Stored)' match = re.search(man_regex, path_info) #print('match: {0}'.format(match)) if match is None: return not_found(environ, start_response) action = match.groups()[1] if (action == 'Gallery'): from cgi import FieldStorage form = FieldStorage(environ=environ) limit = 20 start = 0 if form.has_key("page") and form["page"].value != "": page = int(form["page"].value) if page < 1: page = 1 start = limit * (page - 1) start_response('200 OK', [('Content-type', 'text/plain')]) imsto = ImSto() gallery = imsto.browse(limit, start) import datetime dthandler = lambda obj: obj.isoformat() if isinstance( obj, datetime.datetime) else None if hasattr(imsto, 'close'): imsto.close() return [json.dumps(gallery, default=dthandler)] elif (action == 'Stored'): return stored_process(environ, start_response) #start_response('200 OK', [('Content-type', 'text/plain')]) #return ['Stored'] elif (action == 'env'): from _respond import print_env return print_env(environ, start_response) start_response('200 OK', [('Content-type', 'text/plain')]) return [path_info]
def manage(environ, start_response): path_info = environ.get('PATH_INFO', '') man_regex = r'^/([A-Za-z]+)/(env|Gallery|Stored)' match = re.search(man_regex, path_info) #print('match: {0}'.format(match)) if match is None: return not_found(environ, start_response) action = match.groups()[1] if (action == 'Gallery'): from cgi import FieldStorage form = FieldStorage(environ=environ) limit = 20 start = 0 if form.has_key("page") and form["page"].value != "": page = int(form["page"].value) if page < 1: page = 1 start = limit * (page - 1) start_response('200 OK', [('Content-type', 'text/plain')]) imsto = ImSto() gallery = imsto.browse(limit, start) import datetime dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None if hasattr(imsto, 'close'): imsto.close() return [json.dumps(gallery, default=dthandler)] elif (action == 'Stored'): return stored_process(environ, start_response) #start_response('200 OK', [('Content-type', 'text/plain')]) #return ['Stored'] elif (action == 'env'): from _respond import print_env return print_env(environ, start_response) start_response('200 OK', [('Content-type', 'text/plain')]) return [path_info]
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "hi:q:lt:v", [ "help", "import=", "id=", "list", "test", "verbose", "limit=", "start=" ]) except getopt.error, msg: raise Usage(msg) #print(opts) #print(args) action = None store_file = None # option processing for option, value in opts: if option == "-v": verbose = True if option in ("-h", "--help"): raise Usage(help_message) if option in ("-i", "--import"): store_file = value print('store file: {0}'.format(store_file)) action = 'import' elif option in ("-l", "--list"): action = 'list' elif option in ("-t", "--test"): action = 'test' filename = value elif option in ("-q", "--id"): action = 'get' id = value else: pass print('action: {}'.format(action)) if (action == 'list'): imsto = ImSto() gallery = imsto.browse() for img in gallery['items']: #print(img) print("{0[filename]}\t{0[length]:8,d}".format(img)) return 0 elif (action == 'get') and id is not None: imsto = ImSto() if not imsto.getFs().exists(id): print('not found') return 1 gf = imsto.get(id) #print(gf) print("found: {0.name}\t{0.length}".format(gf)) return 0 elif (action == 'test'): print('filename: %r' % filename) fp = open(filename, 'rb') h = fp.read(32) print(getImageType(h)) return 0