<s> import sys <EOL> import os <EOL> from lacore . async import block <EOL> from twisted . internet import defer <EOL> from lacore . adf . elements import Archive , Meta , Cipher <EOL> from lacore . adf . persist import make_adf <EOL> from lacore . api import RequestsFactory , UploadOperation <EOL> from lacore . storage . s3 import S3Connection <EOL> from lacore . dumper . s3 import S3Dumper <EOL> API_URL = '<STR_LIT>' <EOL> @ block <EOL> @ defer . inlineCallbacks <EOL> def upload ( title , urls , description = None , <EOL> fmt = '<STR_LIT>' , capsule = None , cb = None , ** kwargs ) : <EOL> api = RequestsFactory ( { '<STR_LIT:user>' : '<STR_LIT:test>' , '<STR_LIT>' : '<STR_LIT:test>' , <EOL> '<STR_LIT:url>' : os . getenv ( '<STR_LIT>' , API_URL ) } ) <EOL> cs = yield api . async_capsules ( ) <EOL> for c in cs : <EOL> if c [ '<STR_LIT:id>' ] == int ( capsule ) : <EOL> capsule = c <EOL> break <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" . format ( capsule ) ) <EOL> archive = Archive ( title , Meta ( fmt , Cipher ( '<STR_LIT>' , <NUM_LIT:1> ) ) , <EOL> description = description ) <EOL> op = UploadOperation ( api , archive , capsule , None ) <EOL> status = yield op . status <EOL> c = S3Connection ( ** status ) <EOL> dest = S3Dumper ( connection = c , key = '<STR_LIT>' , <EOL> docs = { '<STR_LIT>' : archive } ) <EOL> list ( dest . dump ( urls , cb ) ) <EOL> dest . docs [ '<STR_LIT>' ] . upload = op . uri <EOL> account = yield api . async_account <EOL> dest . docs [ '<STR_LIT>' ] . meta . email = account [ '<STR_LIT:email>' ] <EOL> dest . docs [ '<STR_LIT>' ] . meta . name = account [ '<STR_LIT>' ] <EOL> c . newkey ( '<STR_LIT>' ) . set_contents_from_string ( <EOL> make_adf ( list ( dest . docs . itervalues ( ) ) ) ) <EOL> yield op . finalize ( dest . docs [ '<STR_LIT>' ] , dest . etags ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from lacli . log import setupLogging <EOL> setupLogging ( <NUM_LIT:4> ) <EOL> upload ( '<STR_LIT:test>' , sys . argv [ <NUM_LIT:2> : ] , capsule = sys . argv [ <NUM_LIT:1> ] ) </s>
