<s> import os , shutil <EOL> import settings <EOL> class BaseVCS ( object ) : <EOL> def __init__ ( self , name , anonymous_access , template = None ) : <EOL> """<STR_LIT>""" <EOL> self . public = anonymous_access <EOL> self . name = name <EOL> self . template = template <EOL> self . config = self . get_config ( ) <EOL> self . _update_path ( ) <EOL> def _update_path ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . public : <EOL> self . path = os . path . abspath ( os . path . join ( self . config [ '<STR_LIT>' ] , self . name ) ) <EOL> self . url = "<STR_LIT>" % ( self . config [ '<STR_LIT>' ] , self . name ) <EOL> else : <EOL> self . path = os . path . abspath ( os . path . join ( self . config [ '<STR_LIT>' ] , self . name ) ) <EOL> self . url = "<STR_LIT>" % ( self . config [ '<STR_LIT>' ] , self . name ) <EOL> def get_config ( self ) : <EOL> """<STR_LIT>""" <EOL> name = self . __class__ . __name__ . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for value in settings . VCS_CONFIG . values ( ) : <EOL> if value [ '<STR_LIT:name>' ] == name : <EOL> return value <EOL> raise Exception ( "<STR_LIT>" % name ) <EOL> def exists ( self ) : <EOL> """<STR_LIT>""" <EOL> return os . path . exists ( self . path ) <EOL> def create ( self ) : <EOL> """<STR_LIT>""" <EOL> NotImplementedError <EOL> def make_public ( self ) : <EOL> """<STR_LIT>""" <EOL> dest = os . path . abspath ( os . path . join ( self . config [ '<STR_LIT>' ] , self . name ) ) <EOL> source = self . path <EOL> shutil . move ( source , dest ) <EOL> self . public = True <EOL> self . _update_path ( ) <EOL> def make_private ( self ) : <EOL> """<STR_LIT>""" <EOL> source = self . path <EOL> dest = os . path . abspath ( os . path . join ( self . config [ '<STR_LIT>' ] , self . name ) ) <EOL> shutil . move ( source , dest ) <EOL> self . public = False <EOL> self . _update_path ( ) <EOL> def delete ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . exists ( ) : <EOL> shutil . rmtree ( self . path ) <EOL> def create_remote ( self , name , description = '<STR_LIT>' , homepage = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def add_remote ( self , name , url , branch = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def update_remote ( self , name , branch = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def list_directory ( self , path ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_absolute_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . url <EOL> def get_current_revision ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_archive ( self , revision = None , tag = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class SubversionRepository ( BaseVCS ) : <EOL> def create ( self ) : <EOL> """<STR_LIT>""" <EOL> import subprocess <EOL> if self . exists ( ) : <EOL> return <EOL> if not os . path . exists ( self . config [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( self . config [ '<STR_LIT>' ] ) <EOL> if not os . path . exists ( self . config [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( self . config [ '<STR_LIT>' ] ) <EOL> cmd = [ "<STR_LIT>" , "<STR_LIT>" , self . path ] <EOL> if self . config [ '<STR_LIT>' ] : <EOL> cmd . extend ( [ "<STR_LIT>" , self . config [ '<STR_LIT>' ] ] ) <EOL> subprocess . check_call ( cmd ) <EOL> if self . template : <EOL> template = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , <EOL> self . template ) <EOL> url = '<STR_LIT>' % self . path <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , template , url , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if self . config [ '<STR_LIT>' ] : <EOL> cmd . extend ( [ "<STR_LIT>" , self . config [ '<STR_LIT>' ] ] ) <EOL> subprocess . check_call ( cmd ) <EOL> def get_current_rev ( self ) : <EOL> from subprocess import PIPE , Popen <EOL> import re <EOL> rev = '<STR_LIT>' <EOL> file_path = os . path . join ( self . path , '<STR_LIT>' ) <EOL> try : <EOL> the_file = open ( file_path , '<STR_LIT:r>' ) <EOL> try : <EOL> rev = the_file . readline ( ) . split ( ) [ <NUM_LIT:0> ] <EOL> finally : <EOL> the_file . close ( ) <EOL> except IOError : <EOL> pass <EOL> return rev <EOL> def list_directory ( self , path ) : <EOL> import pysvn , time <EOL> client = pysvn . Client ( ) <EOL> dirlist = client . list ( "<STR_LIT>" % ( self . path , path ) , <EOL> depth = pysvn . depth . immediates ) <EOL> results = [ ] <EOL> for item , locked in dirlist : <EOL> if item . repos_path == path : <EOL> continue <EOL> results . append ( { <EOL> '<STR_LIT:filename>' : os . path . basename ( item . path ) , <EOL> '<STR_LIT>' : ( item . kind == pysvn . node_kind . dir ) , <EOL> '<STR_LIT:size>' : item . size , <EOL> '<STR_LIT:date>' : time . ctime ( item . time ) , <EOL> '<STR_LIT>' : item . last_author <EOL> } ) <EOL> return results <EOL> class BazaarRepository ( BaseVCS ) : <EOL> pass <EOL> class MercurialRepository ( BaseVCS ) : <EOL> pass <EOL> class GitRepository ( BaseVCS ) : <EOL> def __init__ ( self , name , anonymous_access , template = None ) : <EOL> super ( GitRepository , self ) . __init__ ( name , anonymous_access , template ) <EOL> if not self . name . endswith ( '<STR_LIT>' ) : <EOL> self . name = "<STR_LIT>" % self . name <EOL> self . _update_path ( ) <EOL> def create_remote ( self , name , description = '<STR_LIT>' , homepage = '<STR_LIT>' ) : <EOL> from github2 . client import Github <EOL> github = Github ( username = settings . GITHUB_USER , api_token = settings . GITHUB_API_TOKEN ) <EOL> new_repo = github . repo . create ( name , description , homepage , public = True ) <EOL> commit_url = new_repo . url . replace ( '<STR_LIT>' , '<STR_LIT>' ) + '<STR_LIT>' <EOL> return commit_url <EOL> def add_remote ( self , name , url , branch = None ) : <EOL> import subprocess <EOL> repo_path = self . path <EOL> cmd = [ "<STR_LIT>" % ( repo_path , name , url ) , ] <EOL> try : <EOL> subprocess . check_call ( cmd , shell = True ) <EOL> except : <EOL> pass <EOL> def remove_remote ( self , name ) : <EOL> import subprocess <EOL> repo_path = self . path <EOL> cmd = [ "<STR_LIT>" % ( repo_path , name ) , ] <EOL> try : <EOL> subprocess . check_call ( cmd , shell = True ) <EOL> except : <EOL> pass <EOL> def update_remote ( self , name , branch = None ) : <EOL> import subprocess <EOL> repo_path = self . path <EOL> the_branch = branch or "<STR_LIT>" <EOL> cmd = [ "<STR_LIT>" % ( repo_path , name , branch ) ] <EOL> try : <EOL> subproc = subprocess . Popen ( cmd , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> output = subproc . communicate ( ) <EOL> except : <EOL> pass <EOL> def create ( self ) : <EOL> import subprocess <EOL> if self . exists ( ) : <EOL> return <EOL> if not os . path . exists ( self . config [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( self . config [ '<STR_LIT>' ] ) <EOL> if not os . path . exists ( self . config [ '<STR_LIT>' ] ) : <EOL> os . makedirs ( self . config [ '<STR_LIT>' ] ) <EOL> repo_path = self . path <EOL> os . mkdir ( repo_path , <NUM_LIT:0> <NUM_LIT> ) <EOL> cmd = [ "<STR_LIT>" % repo_path , ] <EOL> subprocess . check_call ( cmd , shell = True ) <EOL> cmd = [ '<STR_LIT>' % ( os . path . join ( settings . BIN_PATH , '<STR_LIT>' ) , repo_path ) ] <EOL> subprocess . check_call ( cmd , shell = True ) <EOL> def get_current_rev ( self ) : <EOL> from subprocess import PIPE , Popen <EOL> cmd = [ '<STR_LIT>' % self . path , ] <EOL> return Popen ( cmd , shell = True , stderr = PIPE , stdout = PIPE ) . communicate ( ) [ <NUM_LIT:0> ] <EOL> def archive ( self , revision = None , tag = None ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
