class AgileFUSE(Operations): def __init__(self, readlib='urllib', verbosity=0): self.verbosity = verbosity self.readlib = readlib self.agile = AgileCLU('agile') self.mc = pylibmc.Client(['127.0.0.1:11211'], binary=True, behaviors={"tcp_nodelay": True, "ketama": True}) self.pool = pylibmc.ClientPool(self.mc, 10) self.cache={} ; self.key={} ; self.cache[0] = {} ; self.key[0] = [] ; self.cache[1] = {} ; self.key[1] = [] self.root = '/' self.path = '/' def __del__(self): try: self.agile.logout() except AttributeError: pass def __call__(self, op, path, *args): if self.verbosity: print '->', op, path, args[0] if args else '' ret = '[Unhandled Exception]' try: ret = getattr(self, op)(self.root + path, *args) return ret except OSError, e: ret = str(e) raise except IOError, e: ret = str(e) raise OSError(*e.args)
def main(*arg): # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") parser.add_option("-r", "--recursive", action="store_true", help="recursive mkdir") (options, args) = parser.parse_args() if len(args) != 1: parser.error("Wrong number of arguments. Exiting.") path = args[0] if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() # check that destination path exists if (agile.exists(path)): if options.verbose: print "File or directory object (%s) already exists. Exiting." % path agile.logout() sys.exit(1) if options.recursive: r = agile.mkdir( path, 1 ) else: r = agile.mkdir( path ) if (r): if options.verbose: print "Directory (%s) has been created. Exiting." % path else: if options.verbose: print "Directory (%s) failed to be created. Suggest trying recursive option (-r). Exiting." % path agile.logout()
def main(): global rule, agile rule = json.loads(rulestr) expire = time.strptime( rule['expire'], '%Y-%m-%d %H:%M:%S' ) now = time.localtime() if now > expire: print "[!] Rule has expired" else: agile = AgileCLU('wylie') try: OK = conditions() if (OK>0): actions() except KeyboardInterrupt: print '[*] Service interrupt detected, terminating.' agile.logout()
def __init__(self, readlib='urllib', verbosity=0): self.verbosity = verbosity self.readlib = readlib self.agile = AgileCLU('agile') self.mc = pylibmc.Client(['127.0.0.1:11211'], binary=True, behaviors={"tcp_nodelay": True, "ketama": True}) self.pool = pylibmc.ClientPool(self.mc, 10) self.cache={} ; self.key={} ; self.cache[0] = {} ; self.key[0] = [] ; self.cache[1] = {} ; self.key[1] = [] self.root = '/' self.path = '/'
def main(*arg): parser = OptionParser( usage= "usage: %prog [options] object path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") object = args[0] path = args[1] if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() egress=agile.mapperurl lfilename = os.path.split(object)[1] u = urllib2.urlopen(egress + object ) dfile = os.path.join(path, lfilename) f = open(dfile, 'wb') f.write(u.read()) f.close() filename, fileext = os.path.splitext(dfile) if(fileext == '.enc'): decrypt_file(agile.encryptionpassword, dfile)
def main(*arg): global fname # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] object path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-c", "--mimetype", dest="mimetype", help="set MIME content-type") group.add_option("-t", "--time", dest="mtime", help="set optional mtime") group.add_option("-e", "--egress", dest="egress", help="set egress policy (PARTIAL, COMPLETE or POLICY)", default="COMPLETE") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") group.add_option("-p", "--progress", action="store_true", help="show transfer progress bar") group.add_option("-z", "--zip", action="store_true", help="compress file before uploading. Including encrypted") group.add_option("-s", "--encrypt", action="store_true", help="Encrypt file before sending it up") parser.add_option_group(group) config = OptionGroup(parser, "Configuration Option") config.add_option("--username", dest="username", help="Agile username") config.add_option("--password", dest="password", help="Agile password") config.add_option("--mapperurl", dest="mapperurl", help="Agile MT URL base") config.add_option("--apiurl", dest="apiurl", help="Agile API URL") config.add_option("--posturl", dest="posturl", help="Agile POST URL") parser.add_option_group(config) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") object = args[0] path = args[1] if (not os.path.isfile(object)): print "Local file object (%s) does not exist. Exiting." % object sys.exit(1) if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() localpath = os.path.dirname(object) localfile = os.path.basename(object) if( options.encrypt ): encrypt_file(agile.encryptionpassword, os.path.join(localpath,localfile)) localfile += ".enc" if( options.zip ): if options.verbose: print "Compressing %s" % (localfile) f_in = open(os.path.join(localpath,localfile), 'rb') localfile += ".gz" f_out = gzip.open(os.path.join(localpath,localfile), 'wb') f_out.writelines(f_in) f_out.close() f_in.close() # check that destination path exists if (not agile.exists(path)): if options.mkdir: r = agile.mkdir( path, 1 ) if (r): if options.verbose: print "Destination path (%s) has been created. Continuing..." % path else: if options.verbose: print "Destination path (%s) failed to be created. Suggest trying --mkdir option. Exiting." % path agile.logout() sys.exit(2) else: if options.verbose: print "Destination path (%s) does not exist. Suggest --mkdir option. Exiting." % path agile.logout() sys.exit(1) if options.filename: fname = options.filename else: fname = localfile if options.mimetype: mimetype = options.mimetype else: mimetype = 'auto' if options.progress: callback = agile.pbar_callback else: callback = None try: result = agile.post( os.path.join(localpath,localfile), path, fname, mimetype, None, options.egress, False, callback ) except (KeyboardInterrupt, SystemExit): print "\nInterupted..." sys.exit(1) if options.verbose: print "%s%s" % (agile.mapperurlstr(),urllib.quote(os.path.join(path,fname))) agile.logout() if( options.zip ): if options.verbose: print "Clearing cached zip file" os.remove(os.path.join(localpath,localfile))
def main(*arg): # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") (options, args) = parser.parse_args() if len(args) != 1: parser.error("Wrong number of arguments. Exiting.") path = args[0] if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() # check that destination path exists if not agile.exists(path): if options.verbose: print "Directory (%s) does not exist. Exiting." % path agile.logout() sys.exit(1) if not agile.dexists(path): if options.verbose: print "Directory (%s) is a file? Exiting." % path agile.logout() sys.exit(2) result = agile.deleteObject(path) if result: print result if options.verbose: print "Directory (%s) was recursively removed." % path else: if options.verbose: print "Directory (%s) was not successfully removed. Exiting." % path agile.logout() sys.exit(3) agile.logout()
def main(*arg): # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") parser.add_option("-r", "--recurse", action="store_true", help="recurse directories") group = OptionGroup(parser, "Output options") group.add_option("-b", "--bytes", action="store_true", help="include file size bytes") group.add_option("-s", "--sizes", action="store_true", help="report things like bytes in human-readable format") group.add_option("-u", "--url", action="store_true", help="include egress URLs") group.add_option("-f", "--filehide", action="store_true", help="hide file objects") group.add_option("-d", "--dirhide", action="store_true", help="hide directory objects") parser.add_option_group(group) """ Placeholder for using command line for profile information profile = OptionGroup(parser, "Profile options") profile.add_option("--username", dest="username", help="Agile username") profile.add_option("--password", dest="password", help="Agile password") profile.add_option("--iprotocol", dest="ingest_protocol", help="Agile ingest protocol", default="https") profile.add_option("--ihostname", dest="ingest_hostname", help="Agile ingest hostname", default="labs-l.upload.llnw.net") profile.add_option("--eprotocol", dest="egress_protocol", help="Agile egress protocol", default="http") profile.add_option("--ehostname", dest="egress_hostname", help="Agile egress hostname", default="global.mt.lldns.net") profile.add_option("--ebase", dest="egress_basepath", help="Agile egress base path" ) parser.add_option_group(profile) """ (options, args) = parser.parse_args() if len(args) != 1 and len(args) != 0: parser.error("Wrong number of arguments. Exiting.") if len(args) == 0: path = '/' else: path = args[0] if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() # check that destination path exists if (not agile.exists(path)): if options.verbose: print "File or directory object (%s) does not exist. Exiting." % path agile.logout() sys.exit(1) else: class DirWalker(object): def walk(self, path, meth): dir = agile.listDir(path, 1000, 0, 1) dir['list'] = sorted(dir['list'], key=str) for item in dir['list']: itemurl = os.path.join(path, item['name']) if not options.dirhide: print "[" + itemurl + "]" if not options.filehide: meth(itemurl) self.walk(itemurl, meth) def FileWalker(object): fl = agile.listFile(object, 1000, 0, 1) items = fl['list'] items = sorted(items, key=itemgetter('name')) items = sorted(items, key=lambda x: x['name'].lower()) for item in items: if options.url: itemurl = "%s%s" % ( agile.mapperurlstr(), urllib.quote(os.path.join(object, item['name']))) else: itemurl = os.path.join(object, item['name']) if options.bytes: if options.sizes: itemurl += " " + sizeof_fmt(item['stat']['size']) else: itemurl += " " + str(item['stat']['size']) + " bytes" print itemurl if options.recurse: DirWalker().walk(path, FileWalker) else: dir = agile.listDir(path, 1000, 0, 1) dir['list'] = sorted(dir['list'], key=str) for item in dir['list']: itemurl = os.path.join(path, item['name']) if not options.dirhide: print "[" + itemurl + "]" FileWalker(path) agile.logout()
def main(*arg): # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") (options, args) = parser.parse_args() if len(args) != 1: parser.error("Wrong number of arguments. Exiting.") path = args[0] if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() # check that destination path exists if not agile.exists(path): if options.verbose: print "Directory (%s) does not exist. Exiting." % path agile.logout() sys.exit(1) if not agile.dexists(path): if options.verbose: print "Directory (%s) is a file? Exiting." % path agile.logout() sys.exit(2) result = agile.deleteObject(path) if result: print result if options.verbose: print "Directory (%s) was recursively removed." % path else: if options.verbose: print "Directory (%s) was not successfully removed. Exiting." % path agile.logout() sys.exit(3) agile.logout()
def main(*arg): global fname # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] object path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-c", "--mimetype", dest="mimetype", help="set MIME content-type") group.add_option("-t", "--time", dest="mtime", help="set optional mtime") group.add_option("-e", "--egress", dest="egress", help="set egress policy (PARTIAL, COMPLETE or POLICY)", default="COMPLETE") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") group.add_option("-p", "--progress", action="store_true", help="show transfer progress bar") group.add_option( "-z", "--zip", action="store_true", help="compress file before uploading. Including encrypted") group.add_option("-s", "--encrypt", action="store_true", help="Encrypt file before sending it up") parser.add_option_group(group) config = OptionGroup(parser, "Configuration Option") config.add_option("--username", dest="username", help="Agile username") config.add_option("--password", dest="password", help="Agile password") config.add_option("--mapperurl", dest="mapperurl", help="Agile MT URL base") config.add_option("--apiurl", dest="apiurl", help="Agile API URL") config.add_option("--posturl", dest="posturl", help="Agile POST URL") parser.add_option_group(config) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") object = args[0] path = args[1] if (not os.path.isfile(object)): print "Local file object (%s) does not exist. Exiting." % object sys.exit(1) if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() localpath = os.path.dirname(object) localfile = os.path.basename(object) if (options.encrypt): encrypt_file(agile.encryptionpassword, os.path.join(localpath, localfile)) localfile += ".enc" if (options.zip): if options.verbose: print "Compressing %s" % (localfile) f_in = open(os.path.join(localpath, localfile), 'rb') localfile += ".gz" f_out = gzip.open(os.path.join(localpath, localfile), 'wb') f_out.writelines(f_in) f_out.close() f_in.close() # check that destination path exists if (not agile.exists(path)): if options.mkdir: r = agile.mkdir(path, 1) if (r): if options.verbose: print "Destination path (%s) has been created. Continuing..." % path else: if options.verbose: print "Destination path (%s) failed to be created. Suggest trying --mkdir option. Exiting." % path agile.logout() sys.exit(2) else: if options.verbose: print "Destination path (%s) does not exist. Suggest --mkdir option. Exiting." % path agile.logout() sys.exit(1) if options.filename: fname = options.filename else: fname = localfile if options.mimetype: mimetype = options.mimetype else: mimetype = 'auto' if options.progress: callback = agile.pbar_callback else: callback = None try: result = agile.post(os.path.join(localpath, localfile), path, fname, mimetype, None, options.egress, False, callback) except (KeyboardInterrupt, SystemExit): print "\nInterupted..." sys.exit(1) if options.verbose: print "%s%s" % (agile.mapperurlstr(), urllib.quote(os.path.join(path, fname))) agile.logout() if (options.zip): if options.verbose: print "Clearing cached zip file" os.remove(os.path.join(localpath, localfile))
def main(*arg): # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") parser.add_option("-r", "--recurse", action="store_true", help="recurse directories") group = OptionGroup(parser, "Output options") group.add_option("-b", "--bytes", action="store_true", help="include file size bytes") group.add_option("-s", "--sizes", action="store_true", help="report things like bytes in human-readable format") group.add_option("-u", "--url", action="store_true", help="include egress URLs") group.add_option("-f", "--filehide", action="store_true", help="hide file objects") group.add_option("-d", "--dirhide", action="store_true", help="hide directory objects") parser.add_option_group(group) """ Placeholder for using command line for profile information profile = OptionGroup(parser, "Profile options") profile.add_option("--username", dest="username", help="Agile username") profile.add_option("--password", dest="password", help="Agile password") profile.add_option("--iprotocol", dest="ingest_protocol", help="Agile ingest protocol", default="https") profile.add_option("--ihostname", dest="ingest_hostname", help="Agile ingest hostname", default="api.agile.lldns.net") profile.add_option("--eprotocol", dest="egress_protocol", help="Agile egress protocol", default="http") profile.add_option("--ehostname", dest="egress_hostname", help="Agile egress hostname", default="global.mt.lldns.net") profile.add_option("--ebase", dest="egress_basepath", help="Agile egress base path" ) parser.add_option_group(profile) """ (options, args) = parser.parse_args() if len(args) != 1 and len(args) != 0: parser.error("Wrong number of arguments. Exiting.") if len(args) == 0: path = '/' else: path = args[0] if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() # check that destination path exists if (not agile.exists(path)): if options.verbose: print "File or directory object (%s) does not exist. Exiting." % path agile.logout() sys.exit(1) else: class DirWalker(object): def walk(self,path,meth): dir = agile.listDir( path, 10000, 0, 1 ) dir['list'] = sorted(dir['list'], key=str) for item in dir['list']: itemurl = os.path.join(path,item['name']) if not options.dirhide: print "["+itemurl+"]" if not options.filehide: meth(itemurl) self.walk(itemurl,meth) def FileWalker(object): cookie = 0 pagesize = 10000 while True: fl = agile.listFile(object, pagesize, cookie, 1) items = fl['list'] items = sorted( items, key=itemgetter('name')) items = sorted( items, key=lambda x: x['name'].lower()) for item in items: if options.url: itemurl = "%s%s" % (agile.mapperurlstr(), urllib.quote(os.path.join( object, item['name'] ))) else: itemurl = os.path.join(object,item['name']) if options.bytes: if options.sizes: itemurl += " "+sizeof_fmt(item['stat']['size']) else: itemurl += " "+str(item['stat']['size'])+" bytes" print itemurl if len(items) < pagesize: break else: cookie +=pagesize if options.recurse: DirWalker().walk(path,FileWalker) else: dir = agile.listDir( path, 10000, 0, 1 ) dir['list'] = sorted(dir['list'], key=str) for item in dir['list']: itemurl = os.path.join(path,item['name']) if not options.dirhide: print "["+itemurl+"]" FileWalker(path) agile.logout()
def main(*arg): # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] url path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") parser.add_option_group(group) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") url = args[0] path = args[1] if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() # check that destination path exists if (not agile.exists(path)): if options.mkdir: r = agile.mkdir(path, 1) if (r): if options.verbose: print "Destination path (%s) has been created. Continuing..." % path else: if options.verbose: print "Destination path (%s) failed to be created. Suggest trying --mkdir option. Exiting." % path agile.logout() sys.exit(2) else: if options.verbose: print "Destination path (%s) does not exist. Suggest --mkdir option. Exiting." % path agile.logout() sys.exit(1) o = urlparse(url) if options.filename: fname = options.filename else: fname = urllib.unquote(os.path.basename(o.path)) r = agile.fetchFileHTTP(os.path.join(path, fname), url) if options.verbose: print "%s%s" % (agile.mapperurlstr(), urllib.quote(os.path.join(path, fname))) agile.logout()
def main(*arg): # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") parser.add_option("-r", "--recursive", action="store_true", help="recursive mkdir") (options, args) = parser.parse_args() if len(args) != 1: parser.error("Wrong number of arguments. Exiting.") path = args[0] if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() # check that destination path exists if (agile.exists(path)): if options.verbose: print "File or directory object (%s) already exists. Exiting." % path agile.logout() sys.exit(1) if options.recursive: r = agile.mkdir(path, 1) else: r = agile.mkdir(path) if (r): if options.verbose: print "Directory (%s) has been created. Exiting." % path else: if options.verbose: print "Directory (%s) failed to be created. Suggest trying recursive option (-r). Exiting." % path agile.logout()
def main(*arg): # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] url path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") parser.add_option_group(group) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") url = args[0] path = args[1] if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() # check that destination path exists if (not agile.exists(path)): if options.mkdir: r = agile.mkdir( path, 1 ) if (r): if options.verbose: print "Destination path (%s) has been created. Continuing..." % path else: if options.verbose: print "Destination path (%s) failed to be created. Suggest trying --mkdir option. Exiting." % path agile.logout() sys.exit(2) else: if options.verbose: print "Destination path (%s) does not exist. Suggest --mkdir option. Exiting." % path agile.logout() sys.exit(1) o = urlparse( url ) if options.filename: fname = options.filename else: fname = urllib.unquote( os.path.basename( o.path ) ) r = agile.fetchFileHTTP( os.path.join(path,fname), url ) if options.verbose: print "%s%s" % (agile.mapperurlstr(),urllib.quote(os.path.join(path,fname))) agile.logout()
def main(*arg): global fname, pbar # parse command line and associated helper parser = OptionParser(usage="usage: %prog [options] object path", version="%prog (AgileCLU " + AgileCLU.__version__ + ")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-c", "--mimetype", dest="mimetype", help="set MIME content-type") group.add_option("-t", "--time", dest="mtime", help="set optional mtime") group.add_option("-e", "--egress", dest="egress", help="set egress policy (PARTIAL, COMPLETE or POLICY)") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") group.add_option("-p", "--progress", action="store_true", help="show transfer progress bar") parser.add_option_group(group) config = OptionGroup(parser, "Configuration Option") config.add_option("--username", dest="username", help="Agile username") config.add_option("--password", dest="password", help="Agile password") config.add_option("--mapperurl", dest="mapperurl", help="Agile MT URL base") config.add_option("--apiurl", dest="apiurl", help="Agile API URL") config.add_option("--posturl", dest="posturl", help="Agile POST URL") config.add_option("--postmultiurl", dest="postmultiurl", help="Agile POST URL") parser.add_option_group(config) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") object = args[0] path = args[1] if (not os.path.isfile(object)): print "Local file object (%s) does not exist. Exiting." % localfile sys.exit(1) if options.username: agile = AgileCLU(options.username) else: agile = AgileCLU() localpath = os.path.dirname(object) localfile = os.path.basename(object) # REMOVED THE DESTINATION PATH CHECK FROM AGILEPOST # if options.filename: fname = options.filename else: fname = localfile print agile.token print fname print path print os.path.join(path, fname) r = agile.createMultipart(os.path.join(path, fname)) mpid = r['mpid'] splitMultipart(fname, 524288) agile.logout() exit(1) register_openers() # video/mpeg for m2ts if options.progress: datagen, headers = multipart_encode( { "uploadFile": open(object, "rb"), "directory": path, "basename": fname, "expose_egress": "COMPLETE" }, cb=progress_callback) else: datagen, headers = multipart_encode({ "uploadFile": open(object, "rb"), "directory": path, "basename": fname, "expose_egress": "COMPLETE" }) request = Request(agile.posturl, datagen, headers) request.add_header("X-Agile-Authorization", agile.token) if options.mimetype: mimetype = options.mimetype else: mimetype = 'auto' request.add_header("X-Content-Type", mimetype) success = False attempt = 0 while not success: attempt += 1 try: result = urlopen(request).read() if options.progress: pbar.finish() success = True except HTTPError, e: if options.progress: pbar.finish() print '[!] HTTP Error: ', e.code pbar = None success = False except URLError, e: if options.progress: pbar.finish() print '[!] URL Error: ', e.reason pbar = None success = False
def main(*arg): global fname, pbar # parse command line and associated helper parser = OptionParser( usage= "usage: %prog [options] object path", version="%prog (AgileCLU "+AgileCLU.__version__+")") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="be verbose", default=False) parser.add_option("-l", "--login", dest="username", help="use alternate profile") group = OptionGroup(parser, "Handling Options") group.add_option("-r", "--rename", dest="filename", help="rename destination file") group.add_option("-c", "--mimetype", dest="mimetype", help="set MIME content-type") group.add_option("-t", "--time", dest="mtime", help="set optional mtime") group.add_option("-e", "--egress", dest="egress", help="set egress policy (PARTIAL, COMPLETE or POLICY)") group.add_option("-m", "--mkdir", action="store_true", help="create destination path, if it does not exist") group.add_option("-p", "--progress", action="store_true", help="show transfer progress bar") parser.add_option_group(group) config = OptionGroup(parser, "Configuration Option") config.add_option("--username", dest="username", help="Agile username") config.add_option("--password", dest="password", help="Agile password") config.add_option("--mapperurl", dest="mapperurl", help="Agile MT URL base") config.add_option("--apiurl", dest="apiurl", help="Agile API URL") config.add_option("--posturl", dest="posturl", help="Agile POST URL") config.add_option("--postmultiurl", dest="postmultiurl", help="Agile POST URL") parser.add_option_group(config) (options, args) = parser.parse_args() if len(args) != 2: parser.error("Wrong number of arguments. Exiting.") object = args[0] path = args[1] if (not os.path.isfile(object)): print "Local file object (%s) does not exist. Exiting." % localfile sys.exit(1) if options.username: agile = AgileCLU( options.username ) else: agile = AgileCLU() localpath = os.path.dirname(object) localfile = os.path.basename(object) # REMOVED THE DESTINATION PATH CHECK FROM AGILEPOST # if options.filename: fname = options.filename else: fname = localfile print agile.token print fname print path print os.path.join(path,fname) r = agile.createMultipart( os.path.join(path,fname) ) mpid = r['mpid'] splitMultipart( fname, 524288 ) agile.logout() exit(1) register_openers() # video/mpeg for m2ts if options.progress: datagen, headers = multipart_encode( { "uploadFile": open(object, "rb"), "directory": path, "basename": fname, "expose_egress": "COMPLETE" }, cb=progress_callback) else: datagen, headers = multipart_encode( { "uploadFile": open(object, "rb"), "directory": path, "basename": fname, "expose_egress": "COMPLETE" } ) request = Request(agile.posturl, datagen, headers) request.add_header("X-Agile-Authorization", agile.token) if options.mimetype: mimetype = options.mimetype else: mimetype = 'auto' request.add_header("X-Content-Type", mimetype ) success = False ; attempt = 0 while not success: attempt += 1 try: result = urlopen(request).read() if options.progress: pbar.finish() success = True except HTTPError, e: if options.progress: pbar.finish() print '[!] HTTP Error: ', e.code pbar = None success = False except URLError, e: if options.progress: pbar.finish() print '[!] URL Error: ', e.reason pbar = None success = False