<s> from __future__ import division <EOL> import os <EOL> import glob <EOL> import pyaml <EOL> import sys <EOL> import errno <EOL> import operator <EOL> from pipes import quote <EOL> from lacli . log import getLogger <EOL> from lacli . upload import Upload , UploadState <EOL> from lacli . capsule import archive_capsule <EOL> from lacli . archive import restore_archive <EOL> from lacore . adf . util import archive_size , creation <EOL> from lacore . adf . elements import Archive , Certificate , Meta , Signature <EOL> from lacore . async import block <EOL> from lacli . cmdutil import command <EOL> from lacli . exceptions import PauseEvent <EOL> from lacli . compose import compose <EOL> from lacli . progress import ConsoleProgressHandler <EOL> from lacli . server . interface . ClientInterface . ttypes import ArchiveStatus <EOL> from lacli . basecmd import LaBaseCommand <EOL> from lacli . loginutil import login <EOL> from lacli . certinput import ask_key <EOL> from twisted . internet import defer , reactor , task <EOL> from richtext import RichTextUI as UIClass <EOL> from richtext import format_size <EOL> ui = UIClass ( ) <EOL> class LaCertsCommand ( LaBaseCommand ) : <EOL> """<STR_LIT>""" <EOL> prompt = '<STR_LIT>' <EOL> def makecmd ( self , options ) : <EOL> line = [ ] <EOL> if options [ '<STR_LIT:list>' ] : <EOL> line . append ( "<STR_LIT:list>" ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( options [ "<STR_LIT>" ] ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( quote ( options [ "<STR_LIT>" ] ) ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( options [ "<STR_LIT>" ] ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( options [ "<STR_LIT>" ] ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( options [ "<STR_LIT>" ] ) <EOL> return "<STR_LIT:U+0020>" . join ( line ) <EOL> @ command ( ) <EOL> def do_list ( self ) : <EOL> """<STR_LIT>""" <EOL> certs = self . cache . _for_adf ( '<STR_LIT>' ) <EOL> if not ui . print_certificates_list ( certs , debug = self . debug ) : <EOL> print "<STR_LIT>" <EOL> print <EOL> @ command ( cert_id = str , srm = str ) <EOL> def do_delete ( self , cert_id = None , srm = None ) : <EOL> """<STR_LIT>""" <EOL> srmprompt = "<STR_LIT:\n>" . join ( ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> fileprompt = "<STR_LIT:\n>" . join ( ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> def _countdown ( ) : <EOL> if self . batch : <EOL> return <EOL> print "<STR_LIT>" , cert_id , "<STR_LIT>" , <EOL> for c in ui . countdown ( <NUM_LIT:5> ) : <EOL> yield <EOL> print "<STR_LIT>" <EOL> fname = self . cache . shred_cert ( cert_id , _countdown ( ) , srm ) <EOL> if not fname : <EOL> print "<STR_LIT>" <EOL> elif self . cache . still_exists ( fname ) : <EOL> if not srm : <EOL> print srmprompt <EOL> else : <EOL> print srm , "<STR_LIT>" <EOL> print fileprompt <EOL> print fname <EOL> else : <EOL> print "<STR_LIT>" , cert_id <EOL> @ command ( cert_id = str ) <EOL> def do_export ( self , cert_id = None ) : <EOL> """<STR_LIT>""" <EOL> path = self . cache . export_cert ( cert_id ) <EOL> if path : <EOL> print "<STR_LIT>" <EOL> print path <EOL> else : <EOL> print "<STR_LIT>" <EOL> @ command ( cert_id = str ) <EOL> def do_print ( self , cert_id = None ) : <EOL> """<STR_LIT>""" <EOL> path = self . cache . print_cert ( cert_id ) <EOL> if path : <EOL> print "<STR_LIT>" <EOL> print path <EOL> else : <EOL> print "<STR_LIT>" <EOL> @ command ( filename = unicode ) <EOL> def do_import ( self , filename = None ) : <EOL> """<STR_LIT>""" <EOL> if filename is None : <EOL> cert = self . input ( "<STR_LIT>" ) <EOL> if cert in self . cache . certs ( ) : <EOL> print "<STR_LIT>" <EOL> else : <EOL> title = self . input ( "<STR_LIT>" ) <EOL> key = ask_key ( ) <EOL> if key is not None : <EOL> print "<STR_LIT>" . format ( <EOL> self . cache . save_cert ( { <EOL> '<STR_LIT>' : Archive ( title , <EOL> Meta ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : Certificate ( key ) , <EOL> '<STR_LIT>' : Signature ( aid = cert , uri = '<STR_LIT>' , ) <EOL> } ) [ <NUM_LIT:0> ] ) <EOL> return <EOL> certs = self . cache . certs ( [ filename ] ) <EOL> if len ( certs ) > <NUM_LIT:0> : <EOL> for key , cert in certs . iteritems ( ) : <EOL> if key in self . cache . certs ( ) : <EOL> print "<STR_LIT>" , key , "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" . format ( <EOL> self . cache . import_cert ( filename ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> print "<STR_LIT>" , filename <EOL> class LaCapsuleCommand ( LaBaseCommand ) : <EOL> """<STR_LIT>""" <EOL> prompt = '<STR_LIT>' <EOL> def makecmd ( self , options ) : <EOL> line = [ ] <EOL> if options [ '<STR_LIT:list>' ] : <EOL> line . append ( "<STR_LIT:list>" ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( '<STR_LIT>' ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> return "<STR_LIT:U+0020>" . join ( line ) <EOL> @ login <EOL> @ command ( ) <EOL> def do_list ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> capsules = self . session . capsules ( ) <EOL> n = <NUM_LIT:0> <EOL> if len ( capsules ) : <EOL> ui . print_capsules_header ( ) <EOL> for capsule in capsules : <EOL> n = n + <NUM_LIT:1> <EOL> ui . print_capsules_line ( capsule = { <EOL> '<STR_LIT>' : n , <EOL> '<STR_LIT:size>' : capsule [ '<STR_LIT:size>' ] , <EOL> '<STR_LIT>' : capsule [ '<STR_LIT>' ] , <EOL> '<STR_LIT:title>' : capsule [ '<STR_LIT:title>' ] , <EOL> '<STR_LIT:id>' : capsule [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : capsule [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : capsule [ '<STR_LIT>' ] , <EOL> } ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> except Exception as e : <EOL> print "<STR_LIT>" + str ( e ) <EOL> @ login <EOL> @ command ( capsule = int ) <EOL> def do_archives ( self , capsule = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if capsule is not None : <EOL> capsules = self . session . capsule_ids ( ) <EOL> if capsule not in capsules : <EOL> print "<STR_LIT>" <EOL> return <EOL> capsule = capsules [ capsule ] <EOL> archives = self . session . archives ( ) <EOL> if capsule is not None : <EOL> archives = [ a for a in archives <EOL> if a [ '<STR_LIT>' ] == capsule [ '<STR_LIT>' ] ] <EOL> if len ( archives ) > <NUM_LIT:0> : <EOL> capsules = dict ( <EOL> [ ( c [ '<STR_LIT>' ] , c [ '<STR_LIT:title>' ] ) <EOL> for c in self . session . capsules ( ) ] ) <EOL> ui . print_archives_header ( ) <EOL> for n , archive in enumerate ( archives ) : <EOL> ui . print_archives_line ( archive = { <EOL> '<STR_LIT>' : n + <NUM_LIT:1> , <EOL> '<STR_LIT:size>' : format_size ( int ( archive [ '<STR_LIT:size>' ] ) ) , <EOL> '<STR_LIT:title>' : archive [ '<STR_LIT:title>' ] , <EOL> '<STR_LIT>' : archive [ '<STR_LIT:key>' ] , <EOL> '<STR_LIT>' : archive [ '<STR_LIT>' ] , <EOL> '<STR_LIT:status>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : capsules . get ( archive [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> } ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> except Exception as e : <EOL> print "<STR_LIT>" + str ( e ) <EOL> class LaArchiveCommand ( LaBaseCommand ) : <EOL> """<STR_LIT>""" <EOL> prompt = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( LaArchiveCommand , self ) . __init__ ( * args , ** kwargs ) <EOL> UploadState . init ( self . cache ) <EOL> self . nprocs = None <EOL> self . sandbox = False <EOL> def setopt ( self , options ) : <EOL> try : <EOL> if options [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> self . nprocs = int ( options [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> print "<STR_LIT>" <EOL> raise <EOL> if options [ '<STR_LIT>' ] : <EOL> self . sandbox = True <EOL> def makecmd ( self , options ) : <EOL> self . setopt ( options ) <EOL> line = [ ] <EOL> if '<STR_LIT>' in options and options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> elif options [ '<STR_LIT:list>' ] : <EOL> line . append ( "<STR_LIT:list>" ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> elif options [ '<STR_LIT:status>' ] : <EOL> line . append ( "<STR_LIT:status>" ) <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> line . append ( quote ( '<STR_LIT>' ) ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( quote ( options [ '<STR_LIT>' ] ) ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> elif options [ '<STR_LIT>' ] : <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( options [ "<STR_LIT>" ] ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( quote ( options [ "<STR_LIT>" ] ) ) <EOL> return "<STR_LIT:U+0020>" . join ( line ) <EOL> @ login <EOL> @ command ( index = int , capsule = int ) <EOL> def do_upload ( self , index = <NUM_LIT:1> , capsule = None ) : <EOL> """<STR_LIT>""" <EOL> fname = None <EOL> docs = list ( self . cache . _for_adf ( '<STR_LIT>' ) . iteritems ( ) ) <EOL> docs = sorted ( docs , key = compose ( creation , operator . itemgetter ( <NUM_LIT:1> ) ) ) <EOL> _error = "<STR_LIT>" <EOL> if index <= <NUM_LIT:0> or len ( docs ) < index : <EOL> _error += "<STR_LIT>" <EOL> else : <EOL> fname = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> docs = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> size = docs [ '<STR_LIT>' ] . meta . size <EOL> capsules = self . session . capsule_ids ( <EOL> size if self . safe else None ) <EOL> if capsule is not None : <EOL> capsule = capsules . get ( capsule ) <EOL> elif len ( capsules ) > <NUM_LIT:0> : <EOL> capsule = capsules . itervalues ( ) . next ( ) <EOL> if capsule is None : <EOL> _error += "<STR_LIT>" <EOL> if '<STR_LIT>' not in docs : <EOL> _error += "<STR_LIT>" <EOL> link = False <EOL> else : <EOL> link = docs [ '<STR_LIT>' ] <EOL> if link and fname and capsule : <EOL> if link . upload or link . download : <EOL> print "<STR_LIT>" <EOL> else : <EOL> try : <EOL> with UploadState . get ( <EOL> fname , size , capsule , self . sandbox ) as state : <EOL> handler = ConsoleProgressHandler ( <EOL> maxval = size , fname = fname , state = state ) <EOL> with handler as progq : <EOL> saved = self . upload ( docs , fname , progq , state ) <EOL> if not self . batch : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> status = self . _poll_status ( saved [ '<STR_LIT>' ] ) <EOL> while status is None : <EOL> getLogger ( ) . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> status = self . _poll_status ( saved [ '<STR_LIT>' ] ) <EOL> if status [ '<STR_LIT:status>' ] == "<STR_LIT:error>" : <EOL> print "<STR_LIT>" <EOL> self . cache . upload_error ( fname ) <EOL> state . error ( True ) <EOL> elif status [ '<STR_LIT:status>' ] == "<STR_LIT>" : <EOL> print "<STR_LIT>" <EOL> fname = saved [ '<STR_LIT>' ] <EOL> cert , f = self . cache . save_cert ( <EOL> self . cache . upload_complete ( fname , status ) ) <EOL> if f : <EOL> print "<STR_LIT>" , cert , "<STR_LIT>" , f <EOL> else : <EOL> print "<STR_LIT>" , cert , "<STR_LIT>" <EOL> print "<STR_LIT:U+0020>" . join ( ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> try : <EOL> UploadState . reset ( fname ) <EOL> break <EOL> except OSError as e : <EOL> if i < <NUM_LIT:3> and e . errno == errno . EACCES : <EOL> continue <EOL> else : <EOL> raise e <EOL> else : <EOL> st = status [ '<STR_LIT:status>' ] <EOL> print "<STR_LIT>" , st <EOL> print "<STR_LIT>" <EOL> except PauseEvent : <EOL> print "<STR_LIT>" <EOL> except Exception as e : <EOL> self . cache . upload_error ( fname ) <EOL> getLogger ( ) . debug ( "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" + str ( e ) <EOL> else : <EOL> print _error <EOL> @ defer . inlineCallbacks <EOL> def _poll_status_async ( self , link ) : <EOL> u = yield self . session . upload_status_async ( link ) <EOL> if u [ '<STR_LIT:status>' ] == "<STR_LIT>" or u [ '<STR_LIT:status>' ] == "<STR_LIT:error>" : <EOL> defer . returnValue ( u ) <EOL> else : <EOL> yield task . deferLater ( reactor , <NUM_LIT> , self . _poll_status_async , link ) <EOL> @ block <EOL> def _poll_status ( self , link ) : <EOL> return self . _poll_status_async ( link ) <EOL> @ defer . inlineCallbacks <EOL> def upload_async ( self , docs , fname , progq , state ) : <EOL> archive = docs [ '<STR_LIT>' ] <EOL> auth = docs [ '<STR_LIT>' ] <EOL> path = self . cache . data_file ( docs [ '<STR_LIT>' ] ) <EOL> op = yield self . session . upload ( archive , state ) <EOL> status = yield op . status <EOL> if status [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> if state . uri is None : <EOL> state . save_op ( op ) <EOL> uploader = Upload ( self . session , self . nprocs , self . debug , state ) <EOL> if state . progress < state . size : <EOL> yield uploader . upload ( path , op , progq ) <EOL> status = yield op . finalize ( auth , state . keys ) <EOL> if status [ '<STR_LIT:status>' ] != '<STR_LIT>' : <EOL> account = yield self . session . async_account <EOL> saved = yield self . cache . save_upload ( <EOL> fname , docs , op . uri , account , state . capsule [ '<STR_LIT:title>' ] ) <EOL> defer . returnValue ( saved ) <EOL> def upload ( self , docs , fname , progq , state ) : <EOL> try : <EOL> state . deferred_upload = self . upload_async ( <EOL> docs , fname , progq , state ) <EOL> return state . wait_for_upload ( ) <EOL> except KeyboardInterrupt : <EOL> getLogger ( ) . debug ( "<STR_LIT>" , exc_info = True ) <EOL> state . pause ( ) <EOL> state . wait_for_upload ( ) <EOL> raise PauseEvent ( ) <EOL> @ command ( directory = str , title = unicode , description = unicode ) <EOL> def do_create ( self , directory = None , title = "<STR_LIT>" , description = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if not os . path . isdir ( directory ) : <EOL> print "<STR_LIT>" <EOL> return <EOL> def mycb ( path , rel ) : <EOL> if not path : <EOL> print "<STR_LIT>" <EOL> else : <EOL> if isinstance ( path , unicode ) : <EOL> path = path . encode ( '<STR_LIT>' ) <EOL> print path , "<STR_LIT>" , rel . encode ( '<STR_LIT>' ) <EOL> self . cache . prepare ( title , directory , <EOL> description = description , cb = mycb ) <EOL> print "<STR_LIT>" <EOL> except UnicodeDecodeError as e : <EOL> fsenc = sys . getfilesystemencoding ( ) <EOL> if fsenc != "<STR_LIT>" : <EOL> fsenc += "<STR_LIT>" <EOL> getLogger ( ) . debug ( "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" . format ( <EOL> e . object . encode ( '<STR_LIT>' ) , fsenc ) <EOL> except Exception as e : <EOL> getLogger ( ) . debug ( "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" + str ( e ) <EOL> @ command ( ) <EOL> def do_list ( self ) : <EOL> """<STR_LIT>""" <EOL> archives = list ( self . cache . _for_adf ( '<STR_LIT>' ) . iteritems ( ) ) <EOL> if len ( archives ) : <EOL> ui . print_archives_header ( ) <EOL> bydate = sorted ( archives , <EOL> key = compose ( creation , operator . itemgetter ( <NUM_LIT:1> ) ) ) <EOL> for n , docs in enumerate ( bydate ) : <EOL> fname = docs [ <NUM_LIT:0> ] <EOL> archive = docs [ <NUM_LIT:1> ] <EOL> status = self . cache . archive_status ( fname , archive ) <EOL> cert = "<STR_LIT>" <EOL> if status == ArchiveStatus . Completed : <EOL> status = "<STR_LIT>" <EOL> cert = archive [ '<STR_LIT>' ] . aid <EOL> elif status == ArchiveStatus . InProgress : <EOL> status = "<STR_LIT>" <EOL> if self . verbose : <EOL> cert = archive [ '<STR_LIT>' ] . upload <EOL> elif status == ArchiveStatus . Failed : <EOL> status = "<STR_LIT>" <EOL> if self . verbose : <EOL> cert = archive [ '<STR_LIT>' ] . upload <EOL> elif status == ArchiveStatus . Local : <EOL> status = "<STR_LIT>" <EOL> elif status == ArchiveStatus . Paused : <EOL> status = "<STR_LIT>" <EOL> else : <EOL> status = "<STR_LIT>" <EOL> title = archive [ '<STR_LIT>' ] . title <EOL> size = archive_size ( archive [ '<STR_LIT>' ] ) <EOL> ui . print_archives_line ( archive = { <EOL> '<STR_LIT>' : n + <NUM_LIT:1> , <EOL> '<STR_LIT:size>' : size , <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT:status>' : status , <EOL> '<STR_LIT>' : cert , <EOL> '<STR_LIT>' : archive [ '<STR_LIT>' ] . meta . created , <EOL> '<STR_LIT>' : archive_capsule ( archive ) or '<STR_LIT:->' <EOL> } ) <EOL> if self . debug > <NUM_LIT:2> : <EOL> for doc in archive . itervalues ( ) : <EOL> pyaml . dump ( doc , sys . stdout ) <EOL> print <EOL> print <EOL> else : <EOL> print "<STR_LIT>" <EOL> @ login <EOL> @ command ( index = int ) <EOL> def do_status ( self , index = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> docs = list ( self . cache . _for_adf ( '<STR_LIT>' ) . iteritems ( ) ) <EOL> docs = sorted ( docs , key = compose ( creation , operator . itemgetter ( <NUM_LIT:1> ) ) ) <EOL> uploads = self . cache . _get_uploads ( ) <EOL> if index <= <NUM_LIT:0> or len ( docs ) < index : <EOL> print "<STR_LIT>" <EOL> else : <EOL> fname = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> upload = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> if fname in uploads : <EOL> upload [ '<STR_LIT>' ] . upload = uploads [ fname ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in upload : <EOL> print "<STR_LIT>" <EOL> elif '<STR_LIT>' in upload and upload [ '<STR_LIT>' ] . upload : <EOL> try : <EOL> url = upload [ '<STR_LIT>' ] . upload <EOL> status = self . session . upload_status ( url ) <EOL> if status [ '<STR_LIT:status>' ] == "<STR_LIT>" : <EOL> print "<STR_LIT>" <EOL> cert , f = self . cache . save_cert ( <EOL> self . cache . upload_complete ( fname , status ) ) <EOL> if f : <EOL> print "<STR_LIT>" , cert , "<STR_LIT>" , f <EOL> else : <EOL> print "<STR_LIT>" , cert , "<STR_LIT>" <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> try : <EOL> UploadState . reset ( fname ) <EOL> break <EOL> except OSError as e : <EOL> if i < <NUM_LIT:3> and e . errno == errno . EACCES : <EOL> continue <EOL> else : <EOL> raise e <EOL> print "<STR_LIT:U+0020>" . join ( ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> else : <EOL> print "<STR_LIT>" , status [ '<STR_LIT:status>' ] <EOL> except Exception as e : <EOL> getLogger ( ) . debug ( "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" + str ( e ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> @ command ( path = unicode , dest = unicode , cert_id = str , cert_file = unicode ) <EOL> def do_extract ( self , path = None , dest = None , cert_id = None , cert_file = None ) : <EOL> """<STR_LIT>""" <EOL> if cert_file : <EOL> certs = self . cache . certs ( [ cert_file ] ) <EOL> cert_id = next ( certs . iterkeys ( ) ) <EOL> else : <EOL> certs = self . cache . certs ( ) <EOL> path = os . path . expanduser ( path ) <EOL> if dest : <EOL> dest = os . path . expanduser ( dest ) <EOL> elif self . batch : <EOL> dest = os . path . dirname ( path ) <EOL> else : <EOL> dest = os . getcwd ( ) <EOL> if not os . path . isfile ( path ) : <EOL> print "<STR_LIT>" , path , "<STR_LIT>" <EOL> elif not os . path . isdir ( dest ) : <EOL> print "<STR_LIT>" , dest , "<STR_LIT>" <EOL> else : <EOL> try : <EOL> if cert_id not in certs : <EOL> if len ( certs ) and not self . batch : <EOL> print "<STR_LIT>" <EOL> while cert_id not in certs : <EOL> ui . print_certificates_list ( certs , debug = self . debug ) <EOL> print <EOL> cert_id = raw_input ( "<STR_LIT>" ) <EOL> assert cert_id , "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> def extract ( cert , archive , dest = dest ) : <EOL> def _print ( f ) : <EOL> print "<STR_LIT>" , f <EOL> restore_archive ( archive , path , cert , <EOL> dest . encode ( '<STR_LIT>' ) , <EOL> self . cache . _cache_dir ( <EOL> '<STR_LIT>' , write = True ) , _print ) <EOL> print "<STR_LIT>" <EOL> if cert_id in certs : <EOL> print "<STR_LIT>" , <EOL> print "<STR_LIT>" <EOL> extract ( certs [ cert_id ] [ '<STR_LIT>' ] , certs [ cert_id ] [ '<STR_LIT>' ] ) <EOL> else : <EOL> getLogger ( ) . debug ( <EOL> "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" <EOL> except Exception as e : <EOL> getLogger ( ) . debug ( "<STR_LIT>" , <EOL> exc_info = True ) <EOL> print "<STR_LIT>" + str ( e ) <EOL> def complete_put ( self , text , line , begidx , endidx ) : <EOL> return [ os . path . basename ( x ) for x in glob . glob ( '<STR_LIT>' . format ( line [ <NUM_LIT:4> : ] ) ) ] <EOL> @ command ( index = int ) <EOL> def do_reset ( self , index ) : <EOL> """<STR_LIT>""" <EOL> docs = list ( self . cache . _for_adf ( '<STR_LIT>' ) . iteritems ( ) ) <EOL> docs = sorted ( docs , key = compose ( creation , operator . itemgetter ( <NUM_LIT:1> ) ) ) <EOL> if index <= <NUM_LIT:0> or len ( docs ) < index : <EOL> print "<STR_LIT>" <EOL> else : <EOL> fname = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if UploadState . has_state ( fname ) : <EOL> UploadState . reset ( fname ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> @ command ( index = int , srm = str ) <EOL> def do_delete ( self , index = None , srm = None ) : <EOL> """<STR_LIT>""" <EOL> docs = list ( self . cache . _for_adf ( '<STR_LIT>' ) . iteritems ( ) ) <EOL> docs = sorted ( docs , key = compose ( creation , operator . itemgetter ( <NUM_LIT:1> ) ) ) <EOL> fname = path = None <EOL> if index <= <NUM_LIT:0> or len ( docs ) < index : <EOL> print "<STR_LIT>" <EOL> return <EOL> else : <EOL> fname = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> docs = docs [ index - <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> archive = docs [ '<STR_LIT>' ] <EOL> path = self . cache . data_file ( docs [ '<STR_LIT>' ] ) <EOL> srmprompt = "<STR_LIT:\n>" . join ( ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> fileprompt = "<STR_LIT:\n>" . join ( ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> if not self . batch : <EOL> print "<STR_LIT>" , index , "<STR_LIT>" . format ( <EOL> archive . title . encode ( '<STR_LIT:utf8>' ) ) , <EOL> for c in ui . countdown ( <NUM_LIT:5> ) : <EOL> pass <EOL> print "<STR_LIT>" <EOL> fname = self . cache . shred_archive ( fname , srm ) <EOL> if self . cache . still_exists ( fname ) : <EOL> if not srm : <EOL> print srmprompt <EOL> else : <EOL> print srm , "<STR_LIT>" <EOL> print fileprompt <EOL> print fname <EOL> if path : <EOL> print path <EOL> elif not os . path . exists ( path ) : <EOL> print "<STR_LIT>" , archive . title , <EOL> print "<STR_LIT>" , path <EOL> else : <EOL> self . cache . shred_file ( path , srm ) <EOL> if self . cache . still_exists ( path ) : <EOL> print "<STR_LIT>" , path <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" , archive . title <EOL> class LaFetchCommand ( LaBaseCommand ) : <EOL> """<STR_LIT>""" <EOL> prompt = '<STR_LIT>' <EOL> def makecmd ( self , options ) : <EOL> line = [ "<STR_LIT>" ] <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> if options [ '<STR_LIT>' ] : <EOL> line . append ( options [ '<STR_LIT>' ] ) <EOL> return "<STR_LIT:U+0020>" . join ( line ) <EOL> @ login <EOL> @ command ( archiveid = str , key = str ) <EOL> def do_fetch ( self , archiveid , key = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> archives = [ a for a in self . session . archives ( ) <EOL> if a [ '<STR_LIT:key>' ] == archiveid ] <EOL> if len ( archives ) == <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> elif len ( archives ) > <NUM_LIT:1> : <EOL> print "<STR_LIT>" <EOL> else : <EOL> archive = archives [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , archive [ '<STR_LIT:title>' ] <EOL> print "<STR_LIT>" , archive [ '<STR_LIT:description>' ] <EOL> print "<STR_LIT>" , archive [ '<STR_LIT>' ] . strftime ( "<STR_LIT>" ) <EOL> print "<STR_LIT>" , archive [ '<STR_LIT>' ] . strftime ( "<STR_LIT>" ) <EOL> key = ask_key ( ) if key is None else key . decode ( '<STR_LIT>' ) <EOL> print "<STR_LIT>" . format ( <EOL> self . cache . save_cert ( { <EOL> '<STR_LIT>' : Archive ( archive [ '<STR_LIT:title>' ] , <EOL> Meta ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> description = archive [ '<STR_LIT:description>' ] ) , <EOL> '<STR_LIT>' : Certificate ( key ) , <EOL> '<STR_LIT>' : Signature ( <EOL> aid = archive [ '<STR_LIT:key>' ] , uri = '<STR_LIT>' , <EOL> created = archive [ '<STR_LIT>' ] , <EOL> expires = archive [ '<STR_LIT>' ] ) <EOL> } ) [ <NUM_LIT:0> ] ) <EOL> except Exception as e : <EOL> print "<STR_LIT>" + str ( e ) </s>
