<s> """<STR_LIT>""" <EOL> import shutil <EOL> import subprocess <EOL> import os . path <EOL> import os <EOL> import opus . lib . builder <EOL> APPDIR = "<STR_LIT>" <EOL> class CopyError ( Exception ) : <EOL> pass <EOL> def fromfilesys ( src , dst ) : <EOL> """<STR_LIT>""" <EOL> shutil . copytree ( src , dst ) <EOL> def fromgit ( src , dst ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:#>" in src : <EOL> src , rev = src . split ( "<STR_LIT:#>" , <NUM_LIT:1> ) <EOL> else : <EOL> rev = None <EOL> proc = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , src , dst ] , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT , <EOL> ) <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> ret = proc . wait ( ) <EOL> if ret : <EOL> raise CopyError ( "<STR_LIT>" . format ( output ) ) <EOL> if rev : <EOL> upgradegit ( dst , rev ) <EOL> def fromhg ( src , dst ) : <EOL> if src . startswith ( "<STR_LIT:->" ) or dst . startswith ( "<STR_LIT:->" ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> proc = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" , src , dst ] , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT , <EOL> ) <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> ret = proc . wait ( ) <EOL> if ret : <EOL> raise CopyError ( "<STR_LIT>" . format ( output ) ) <EOL> def install_app ( apppath , appname , apptype , projectdir ) : <EOL> """<STR_LIT>""" <EOL> copy_functions = { <EOL> '<STR_LIT:file>' : fromfilesys , <EOL> '<STR_LIT>' : fromgit , <EOL> '<STR_LIT>' : fromhg , <EOL> } <EOL> try : <EOL> cf = copy_functions [ apptype ] <EOL> except KeyError : <EOL> raise CopyError ( "<STR_LIT>" ) <EOL> dst = os . path . join ( projectdir , APPDIR , appname ) <EOL> cf ( apppath , dst ) <EOL> bare = - <NUM_LIT:1> <EOL> if os . path . exists ( os . path . join ( dst , "<STR_LIT>" ) ) : <EOL> bare = True <EOL> if os . path . exists ( os . path . join ( dst , appname , "<STR_LIT>" ) ) : <EOL> bare = False <EOL> if bare == - <NUM_LIT:1> : <EOL> if os . path . exists ( os . path . join ( dst , "<STR_LIT>" ) ) : <EOL> bare = True <EOL> if os . path . exists ( os . path . join ( dst , appname , "<STR_LIT>" ) ) : <EOL> bare = False <EOL> if bare == - <NUM_LIT:1> : <EOL> if os . path . exists ( os . path . join ( dst , "<STR_LIT>" ) ) : <EOL> bare = True <EOL> if os . path . exists ( os . path . join ( dst , appname , "<STR_LIT>" ) ) : <EOL> bare = False <EOL> if bare == - <NUM_LIT:1> : <EOL> raise CopyError ( "<STR_LIT>" ) <EOL> if bare : <EOL> os . symlink ( dst , os . path . join ( projectdir , appname ) ) <EOL> else : <EOL> os . symlink ( os . path . join ( dst , appname ) , <EOL> os . path . join ( projectdir , appname ) ) <EOL> def upgradefile ( path , to ) : <EOL> raise NotImplementedError ( ) <EOL> def upgradegit ( path , to ) : <EOL> proc = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = path , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT , <EOL> ) <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> ret = proc . wait ( ) <EOL> if ret : <EOL> raise opus . lib . builder . BuildException ( "<STR_LIT>" . format ( ret , output ) ) <EOL> proc = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , to ] , <EOL> cwd = path , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT , <EOL> ) <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> ret = proc . wait ( ) <EOL> if ret : <EOL> raise opus . lib . builder . BuildException ( "<STR_LIT>" . format ( ret , output ) ) <EOL> upgrade_functions = { <EOL> '<STR_LIT:file>' : upgradefile , <EOL> '<STR_LIT>' : upgradegit , <EOL> '<STR_LIT>' : upgradefile , <EOL> } <EOL> def is_git ( apppath ) : <EOL> return os . path . exists ( os . path . join ( apppath , "<STR_LIT>" ) ) <EOL> def is_hg ( apppath ) : <EOL> return os . path . exists ( os . path . join ( apppath , "<STR_LIT>" ) ) <EOL> def introspect_source ( apppath ) : <EOL> """<STR_LIT>""" <EOL> if is_git ( apppath ) : <EOL> return '<STR_LIT>' <EOL> if is_hg ( apppath ) : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT:file>' <EOL> def file_version ( apppath ) : <EOL> return "<STR_LIT>" <EOL> def git_version ( apppath ) : <EOL> proc = subprocess . Popen ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> cwd = apppath , <EOL> ) <EOL> output = proc . communicate ( ) [ <NUM_LIT:0> ] <EOL> ret = proc . wait ( ) <EOL> if ret : <EOL> raise opus . lib . builder . BuildException ( "<STR_LIT>" . format ( ret , output ) ) <EOL> return output <EOL> version_functions = { <EOL> '<STR_LIT:file>' : file_version , <EOL> '<STR_LIT>' : git_version , <EOL> } </s>
