<s> import sys <EOL> import os <EOL> import tempfile <EOL> import shutil <EOL> import subprocess <EOL> from optparse import OptionParser <EOL> from pkg_resources import working_set , Requirement <EOL> from openmdao . util . fileutil import build_directory , onerror <EOL> _setup_py_template = '''<STR_LIT>''' <EOL> _ns_template = '''<STR_LIT>''' <EOL> def mkpseudo ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv [ <NUM_LIT:1> : ] <EOL> parser = OptionParser ( ) <EOL> parser . usage = "<STR_LIT>" <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , dest = '<STR_LIT>' , default = '<STR_LIT:.>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT>" , type = "<STR_LIT:string>" , dest = '<STR_LIT>' , default = [ ] , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT>" , type = "<STR_LIT:string>" , dest = '<STR_LIT>' , default = [ ] , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( argv ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> parser . print_help ( ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> name = args [ <NUM_LIT:0> ] <EOL> names = name . split ( '<STR_LIT:.>' ) <EOL> version = args [ <NUM_LIT:1> ] <EOL> for i , url in enumerate ( options . deplinks ) : <EOL> if not url . startswith ( '<STR_LIT>' ) and not url . startswith ( '<STR_LIT>' ) : <EOL> options . deplinks [ i ] = "<STR_LIT>" % url <EOL> dest = os . path . abspath ( os . path . expandvars ( os . path . expanduser ( options . dest ) ) ) <EOL> if len ( options . reqs ) == <NUM_LIT:0> and options . dist : <EOL> print "<STR_LIT>" <EOL> options . dist = False <EOL> nspkgs = [ ] <EOL> for i , nm in enumerate ( names [ : - <NUM_LIT:1> ] ) : <EOL> nspkgs . append ( '<STR_LIT:.>' . join ( names [ : i + <NUM_LIT:1> ] ) ) <EOL> dists = working_set . resolve ( [ Requirement . parse ( r ) for r in options . reqs ] ) <EOL> dset = set ( [ ( "<STR_LIT:%s>" % d ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) for d in dists ] ) <EOL> setup_options = { <EOL> '<STR_LIT>' : list ( dset ) , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT:version>' : version , <EOL> '<STR_LIT>' : options . deplinks , <EOL> '<STR_LIT>' : nspkgs , <EOL> } <EOL> startdir = os . getcwd ( ) <EOL> if options . dist : <EOL> tdir = tempfile . mkdtemp ( ) <EOL> else : <EOL> tdir = dest <EOL> try : <EOL> os . chdir ( tdir ) <EOL> rnames = names [ : : - <NUM_LIT:1> ] <EOL> for i , ns in enumerate ( rnames ) : <EOL> if i == <NUM_LIT:0> : <EOL> dct = { '<STR_LIT>' : '<STR_LIT>' } <EOL> else : <EOL> dct = { <EOL> '<STR_LIT>' : _ns_template , <EOL> rnames [ i - <NUM_LIT:1> ] : dct , <EOL> } <EOL> dct = { names [ <NUM_LIT:0> ] : dct } <EOL> dirstruct = { <EOL> name : { <EOL> '<STR_LIT>' : _setup_py_template % setup_options , <EOL> '<STR_LIT:src>' : dct , <EOL> } , <EOL> } <EOL> if not options . dist : <EOL> if os . path . exists ( name ) : <EOL> print "<STR_LIT>" % name <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> build_directory ( dirstruct ) <EOL> os . chdir ( name ) <EOL> if options . dist : <EOL> tarname = os . path . join ( dest , "<STR_LIT>" % ( name , version ) ) <EOL> zipname = os . path . join ( dest , "<STR_LIT>" % ( name , version ) ) <EOL> for fname in [ tarname , zipname ] : <EOL> if os . path . exists ( fname ) : <EOL> print "<STR_LIT>" % fname <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> cmd = [ sys . executable , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , dest ] <EOL> subprocess . check_call ( cmd ) <EOL> finally : <EOL> os . chdir ( startdir ) <EOL> if options . dist : <EOL> shutil . rmtree ( tdir , onerror = onerror ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> mkpseudo ( sys . argv [ <NUM_LIT:1> : ] ) </s>
