<s> import os <EOL> import configparser <EOL> import shutil <EOL> import shlex <EOL> import shell <EOL> import shouter <EOL> config = None <EOL> configfile = None <EOL> user = None <EOL> password = None <EOL> def read ( configname = None ) : <EOL> if not configname : <EOL> global configfile <EOL> configname = configfile <EOL> parsedconfig = configparser . ConfigParser ( ) <EOL> if len ( parsedconfig . read ( configname ) ) < <NUM_LIT:1> : <EOL> raise IOError ( '<STR_LIT>' % configname ) <EOL> generalsection = parsedconfig [ '<STR_LIT>' ] <EOL> migrationsectionname = '<STR_LIT>' <EOL> migrationsection = parsedconfig [ migrationsectionname ] <EOL> miscsectionname = '<STR_LIT>' <EOL> global user <EOL> if not user : <EOL> user = generalsection [ '<STR_LIT>' ] <EOL> global password <EOL> if not password : <EOL> password = generalsection [ '<STR_LIT>' ] <EOL> repositoryurl = generalsection [ '<STR_LIT>' ] <EOL> scmcommand = generalsection . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> shell . logcommands = parsedconfig . get ( miscsectionname , '<STR_LIT>' , fallback = "<STR_LIT:False>" ) == "<STR_LIT:True>" <EOL> shell . setencoding ( generalsection . get ( '<STR_LIT>' ) ) <EOL> workspace = shlex . quote ( generalsection [ '<STR_LIT>' ] ) <EOL> gitreponame = generalsection [ '<STR_LIT>' ] <EOL> useexistingworkspace = generalsection . get ( '<STR_LIT>' , "<STR_LIT:False>" ) <EOL> useprovidedhistory = migrationsection . get ( '<STR_LIT>' , "<STR_LIT:False>" ) <EOL> useautomaticconflictresolution = migrationsection . get ( '<STR_LIT>' , "<STR_LIT:False>" ) <EOL> maxchangesetstoaccepttogether = migrationsection . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> workdirectory = generalsection . get ( '<STR_LIT>' , os . getcwd ( ) ) <EOL> streamname = shlex . quote ( migrationsection [ '<STR_LIT>' ] . strip ( ) ) <EOL> previousstreamname = migrationsection . get ( '<STR_LIT>' , '<STR_LIT>' ) . strip ( ) <EOL> baselines = getinitialcomponentbaselines ( migrationsection . get ( '<STR_LIT>' ) ) <EOL> ignorefileextensionsproperty = parsedconfig . get ( miscsectionname , '<STR_LIT>' , fallback = '<STR_LIT>' ) <EOL> ignorefileextensions = parsesplittedproperty ( ignorefileextensionsproperty ) <EOL> ignoredirectoriessproperty = parsedconfig . get ( miscsectionname , '<STR_LIT>' , fallback = '<STR_LIT>' ) <EOL> ignoredirectories = parsesplittedproperty ( ignoredirectoriessproperty ) <EOL> includecomponentroots = parsedconfig . get ( miscsectionname , '<STR_LIT>' , fallback = "<STR_LIT:False>" ) <EOL> commitmessageprefix = migrationsection . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> gitattributesproperty = parsedconfig . get ( migrationsectionname , '<STR_LIT>' , fallback = '<STR_LIT>' ) <EOL> gitattributes = parsesplittedproperty ( gitattributesproperty ) <EOL> configbuilder = Builder ( ) . setuser ( user ) . setpassword ( password ) . setrepourl ( repositoryurl ) . setscmcommand ( scmcommand ) <EOL> configbuilder . setworkspace ( workspace ) . setgitreponame ( gitreponame ) . setrootfolder ( os . getcwd ( ) ) <EOL> configbuilder . setuseexistingworkspace ( useexistingworkspace ) . setuseprovidedhistory ( useprovidedhistory ) <EOL> configbuilder . setuseautomaticconflictresolution ( useautomaticconflictresolution ) <EOL> configbuilder . setmaxchangesetstoaccepttogether ( maxchangesetstoaccepttogether ) <EOL> configbuilder . setworkdirectory ( workdirectory ) . setstreamname ( streamname ) . setinitialcomponentbaselines ( baselines ) <EOL> configbuilder . setpreviousstreamname ( previousstreamname ) <EOL> configbuilder . setignorefileextensions ( ignorefileextensions ) <EOL> configbuilder . setignoredirectories ( ignoredirectories ) <EOL> configbuilder . setincludecomponentroots ( includecomponentroots ) . setcommitmessageprefix ( commitmessageprefix ) <EOL> configbuilder . setgitattributes ( gitattributes ) <EOL> global config <EOL> config = configbuilder . build ( ) <EOL> return config <EOL> def get ( ) : <EOL> if not config : <EOL> read ( ) <EOL> return config <EOL> def setconfigfile ( newconfigfile ) : <EOL> global configfile <EOL> configfile = newconfigfile <EOL> def setUser ( newuser ) : <EOL> global user <EOL> user = newuser <EOL> def setPassword ( newpassword ) : <EOL> global password <EOL> password = newpassword <EOL> def getinitialcomponentbaselines ( definedbaselines ) : <EOL> initialcomponentbaselines = [ ] <EOL> if definedbaselines : <EOL> componentbaselines = definedbaselines . split ( "<STR_LIT:U+002C>" ) <EOL> for entry in componentbaselines : <EOL> componentbaseline = entry . split ( "<STR_LIT:=>" ) <EOL> component = componentbaseline [ <NUM_LIT:0> ] . strip ( ) <EOL> baseline = componentbaseline [ <NUM_LIT:1> ] . strip ( ) <EOL> initialcomponentbaselines . append ( ComponentBaseLineEntry ( component , baseline , component , baseline ) ) <EOL> return initialcomponentbaselines <EOL> def parsesplittedproperty ( property , separator = '<STR_LIT:;>' ) : <EOL> """<STR_LIT>""" <EOL> properties = [ ] <EOL> if property and len ( property ) > <NUM_LIT:0> : <EOL> for splittedproperty in property . split ( separator ) : <EOL> properties . append ( splittedproperty . strip ( ) ) <EOL> return properties <EOL> class Builder : <EOL> def __init__ ( self ) : <EOL> self . user = "<STR_LIT>" <EOL> self . password = "<STR_LIT>" <EOL> self . repourl = "<STR_LIT>" <EOL> self . scmcommand = "<STR_LIT>" <EOL> self . workspace = "<STR_LIT>" <EOL> self . useexistingworkspace = "<STR_LIT>" <EOL> self . useprovidedhistory = "<STR_LIT>" <EOL> self . useautomaticconflictresolution = "<STR_LIT>" <EOL> self . maxchangesetstoaccepttogether = "<STR_LIT>" <EOL> self . workdirectory = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> self . rootFolder = self . workdirectory <EOL> self . logFolder = self . rootFolder + os . sep + "<STR_LIT>" <EOL> self . hasCreatedLogFolder = os . path . exists ( self . logFolder ) <EOL> self . initialcomponentbaselines = "<STR_LIT>" <EOL> self . streamname = "<STR_LIT>" <EOL> self . gitreponame = "<STR_LIT>" <EOL> self . clonedgitreponame = "<STR_LIT>" <EOL> self . previousstreamname = "<STR_LIT>" <EOL> self . ignorefileextensions = "<STR_LIT>" <EOL> self . ignoredirectories = "<STR_LIT>" <EOL> self . includecomponentroots = "<STR_LIT>" <EOL> self . commitmessageprefix = "<STR_LIT>" <EOL> self . gitattributes = "<STR_LIT>" <EOL> def setuser ( self , user ) : <EOL> self . user = user <EOL> return self <EOL> def setpassword ( self , password ) : <EOL> self . password = password <EOL> return self <EOL> def setrepourl ( self , repourl ) : <EOL> self . repourl = repourl <EOL> return self <EOL> def setscmcommand ( self , scmcommand ) : <EOL> self . scmcommand = scmcommand <EOL> return self <EOL> def setworkspace ( self , workspace ) : <EOL> self . workspace = workspace <EOL> return self <EOL> def setworkdirectory ( self , workdirectory ) : <EOL> self . workdirectory = workdirectory <EOL> return self <EOL> def setrootfolder ( self , rootfolder ) : <EOL> self . rootFolder = rootfolder <EOL> return self <EOL> def setlogfolder ( self , logfolder ) : <EOL> self . logFolder = logfolder <EOL> return self <EOL> def setinitialcomponentbaselines ( self , initialcomponentbaselines ) : <EOL> self . initialcomponentbaselines = initialcomponentbaselines <EOL> return self <EOL> def setstreamname ( self , streamname ) : <EOL> self . streamname = streamname <EOL> return self <EOL> def setgitreponame ( self , reponame ) : <EOL> self . gitreponame = reponame <EOL> self . clonedgitreponame = reponame [ : - <NUM_LIT:4> ] <EOL> return self <EOL> def setuseexistingworkspace ( self , useexistingworkspace ) : <EOL> self . useexistingworkspace = self . isenabled ( useexistingworkspace ) <EOL> return self <EOL> def setuseprovidedhistory ( self , useprovidedhistory ) : <EOL> self . useprovidedhistory = self . isenabled ( useprovidedhistory ) <EOL> return self <EOL> def setuseautomaticconflictresolution ( self , useautomaticconflictresolution ) : <EOL> self . useautomaticconflictresolution = self . isenabled ( useautomaticconflictresolution ) <EOL> return self <EOL> def setmaxchangesetstoaccepttogether ( self , maxchangesetstoaccepttogether ) : <EOL> self . maxchangesetstoaccepttogether = int ( maxchangesetstoaccepttogether ) <EOL> return self <EOL> def setpreviousstreamname ( self , previousstreamname ) : <EOL> self . previousstreamname = previousstreamname <EOL> return self <EOL> def setignorefileextensions ( self , ignorefileextensions ) : <EOL> self . ignorefileextensions = ignorefileextensions <EOL> return self <EOL> def setignoredirectories ( self , ignoreirectories ) : <EOL> self . ignoredirectories = ignoreirectories <EOL> return self <EOL> def setincludecomponentroots ( self , includecomponentroots ) : <EOL> self . includecomponentroots = self . isenabled ( includecomponentroots ) <EOL> return self <EOL> def setcommitmessageprefix ( self , commitmessageprefix ) : <EOL> self . commitmessageprefix = commitmessageprefix <EOL> return self <EOL> def setgitattributes ( self , gitattributes ) : <EOL> self . gitattributes = gitattributes <EOL> return self <EOL> @ staticmethod <EOL> def isenabled ( stringwithbooleanexpression ) : <EOL> return stringwithbooleanexpression == "<STR_LIT:True>" <EOL> def build ( self ) : <EOL> return ConfigObject ( self . user , self . password , self . repourl , self . scmcommand , self . workspace , <EOL> self . useexistingworkspace , self . workdirectory , self . initialcomponentbaselines , <EOL> self . streamname , self . gitreponame , self . useprovidedhistory , <EOL> self . useautomaticconflictresolution , self . maxchangesetstoaccepttogether , self . clonedgitreponame , self . rootFolder , <EOL> self . previousstreamname , self . ignorefileextensions , self . ignoredirectories , self . includecomponentroots , <EOL> self . commitmessageprefix , self . gitattributes ) <EOL> class ConfigObject : <EOL> def __init__ ( self , user , password , repourl , scmcommand , workspace , useexistingworkspace , workdirectory , <EOL> initialcomponentbaselines , streamname , gitreponame , useprovidedhistory , <EOL> useautomaticconflictresolution , maxchangesetstoaccepttogether , clonedgitreponame , rootfolder , previousstreamname , <EOL> ignorefileextensions , ignoredirectories , includecomponentroots , commitmessageprefix , gitattributes ) : <EOL> self . user = user <EOL> self . password = password <EOL> self . repo = repourl <EOL> self . scmcommand = scmcommand <EOL> self . workspace = workspace <EOL> self . useexistingworkspace = useexistingworkspace <EOL> self . useprovidedhistory = useprovidedhistory <EOL> self . useautomaticconflictresolution = useautomaticconflictresolution <EOL> self . maxchangesetstoaccepttogether = maxchangesetstoaccepttogether <EOL> self . workDirectory = workdirectory <EOL> self . initialcomponentbaselines = initialcomponentbaselines <EOL> self . streamname = streamname <EOL> self . gitRepoName = gitreponame <EOL> self . clonedGitRepoName = clonedgitreponame <EOL> self . rootFolder = rootfolder <EOL> self . logFolder = rootfolder + os . sep + "<STR_LIT>" <EOL> self . hasCreatedLogFolder = os . path . exists ( self . logFolder ) <EOL> self . streamuuid = "<STR_LIT>" <EOL> self . previousstreamname = previousstreamname <EOL> self . previousstreamuuid = "<STR_LIT>" <EOL> self . ignorefileextensions = ignorefileextensions <EOL> self . ignoredirectories = ignoredirectories <EOL> self . includecomponentroots = includecomponentroots <EOL> self . commitmessageprefix = commitmessageprefix <EOL> self . gitattributes = gitattributes <EOL> def getlogpath ( self , filename ) : <EOL> if not self . hasCreatedLogFolder : <EOL> os . makedirs ( self . logFolder ) <EOL> self . hasCreatedLogFolder = True <EOL> return self . logFolder + os . sep + filename <EOL> def deletelogfolder ( self ) : <EOL> if self . hasCreatedLogFolder : <EOL> shutil . rmtree ( self . logFolder ) <EOL> self . hasCreatedLogFolder = False <EOL> def gethistorypath ( self , filename ) : <EOL> historypath = self . rootFolder + os . sep + "<STR_LIT>" <EOL> return historypath + os . sep + filename <EOL> def collectstreamuuid ( self , streamname ) : <EOL> if not streamname : <EOL> return <EOL> shouter . shout ( "<STR_LIT>" + streamname ) <EOL> showuuidcommand = "<STR_LIT>" % ( <EOL> self . scmcommand , self . repo , streamname ) <EOL> output = shell . getoutput ( showuuidcommand ) <EOL> splittedfirstline = output [ <NUM_LIT:0> ] . split ( "<STR_LIT:U+0020>" ) <EOL> streamuuid = splittedfirstline [ <NUM_LIT:0> ] . strip ( ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return streamuuid <EOL> def collectstreamuuids ( self ) : <EOL> self . streamuuid = self . collectstreamuuid ( self . streamname ) <EOL> self . previousstreamuuid = self . collectstreamuuid ( self . previousstreamname ) <EOL> class ComponentBaseLineEntry : <EOL> def __init__ ( self , component , baseline , componentname , baselinename ) : <EOL> self . component = component <EOL> self . baseline = baseline <EOL> self . componentname = componentname <EOL> self . baselinename = baselinename </s>
