<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> from copy import copy , deepcopy <EOL> from glob import glob <EOL> from larch import ValidateLarchPlugin <EOL> MODNAME = '<STR_LIT>' <EOL> def _copy ( obj , ** kws ) : <EOL> """<STR_LIT>""" <EOL> return copy ( obj ) <EOL> def _deepcopy ( obj , ** kws ) : <EOL> """<STR_LIT>""" <EOL> return deepcopy ( obj ) <EOL> @ ValidateLarchPlugin <EOL> def _parent ( name , _larch = None , ** kw ) : <EOL> "<STR_LIT>" <EOL> print ( _larch . symtable . _lookup ( name , create = False ) ) <EOL> @ ValidateLarchPlugin <EOL> def _ls ( directory = '<STR_LIT:.>' , _larch = None , ** kws ) : <EOL> """<STR_LIT>""" <EOL> directory . strip ( ) <EOL> if len ( directory ) == <NUM_LIT:0> : <EOL> arg = '<STR_LIT:.>' <EOL> if os . path . isdir ( directory ) : <EOL> ret = os . listdir ( directory ) <EOL> else : <EOL> ret = glob ( directory ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> for i in range ( len ( ret ) ) : <EOL> ret [ i ] = ret [ i ] . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> return ret <EOL> def _cwd ( ** kws ) : <EOL> "<STR_LIT>" <EOL> ret = os . getcwd ( ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> ret = ret . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> return ret <EOL> def _cd ( name , ** kws ) : <EOL> """<STR_LIT>""" <EOL> name = name . strip ( ) <EOL> if name : <EOL> os . chdir ( name ) <EOL> ret = os . getcwd ( ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> ret = ret . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> return ret <EOL> def _mkdir ( name , mode = <NUM_LIT> , ** kws ) : <EOL> """<STR_LIT>""" <EOL> return os . makedirs ( name , mode = mode ) <EOL> @ ValidateLarchPlugin <EOL> def show_more ( text , filename = None , writer = None , <EOL> pagelength = <NUM_LIT:30> , prefix = '<STR_LIT>' , _larch = None , ** kws ) : <EOL> """<STR_LIT>""" <EOL> txt = text [ : ] <EOL> if isinstance ( txt , ( str , unicode ) ) : <EOL> txt = txt . split ( '<STR_LIT:\n>' ) <EOL> if len ( txt ) < <NUM_LIT:1> : <EOL> return <EOL> prompt = '<STR_LIT>' <EOL> ps = "<STR_LIT>" % prompt <EOL> if filename : <EOL> ps = "<STR_LIT>" % ( prompt , filename ) <EOL> if writer is None : <EOL> writer = sys . stdout <EOL> i = <NUM_LIT:0> <EOL> for i in range ( len ( txt ) ) : <EOL> if txt [ i ] . endswith ( '<STR_LIT:\n>' ) : <EOL> _larch . writer . write ( "<STR_LIT>" % ( prefix , txt [ i ] ) ) <EOL> else : <EOL> writer . write ( "<STR_LIT>" % ( prefix , txt [ i ] ) ) <EOL> i = i + <NUM_LIT:1> <EOL> if i % pagelength == <NUM_LIT:0> : <EOL> try : <EOL> x = raw_input ( ps % ( <NUM_LIT> * i / len ( txt ) ) ) <EOL> if x in ( '<STR_LIT:q>' , '<STR_LIT>' ) : return <EOL> except KeyboardInterrupt : <EOL> writer . write ( "<STR_LIT:\n>" ) <EOL> return <EOL> @ ValidateLarchPlugin <EOL> def _more ( fname , pagelength = <NUM_LIT:32> , _larch = None , ** kws ) : <EOL> """<STR_LIT>""" <EOL> output = _larch . writer . write <EOL> if not os . path . exists ( fname ) : <EOL> output ( "<STR_LIT>" % fname ) <EOL> return <EOL> elif not os . path . isfile ( fname ) : <EOL> output ( "<STR_LIT>" % fname ) <EOL> return <EOL> try : <EOL> text = open ( fname , '<STR_LIT:r>' ) . readlines ( ) <EOL> except IOError : <EOL> output ( "<STR_LIT>" % fname ) <EOL> return <EOL> show_more ( text , filename = fname , _larch = _larch , <EOL> pagelength = pagelength , ** kws ) <EOL> def initializeLarchPlugin ( _larch = None ) : <EOL> """<STR_LIT>""" <EOL> cmds = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if _larch is not None : <EOL> _larch . symtable . _sys . valid_commands . extend ( cmds ) <EOL> def registerLarchPlugin ( ) : <EOL> return ( '<STR_LIT>' , { '<STR_LIT>' : _copy , '<STR_LIT>' : _deepcopy , <EOL> '<STR_LIT>' : _more , '<STR_LIT>' : _parent , <EOL> '<STR_LIT>' : _ls , '<STR_LIT>' : _mkdir , <EOL> '<STR_LIT>' : _cd , '<STR_LIT>' : _cwd } ) </s>
