-
-class SvnRepository:
- type = "svn"
-
- def __init__(self, path, options):
- self.path = path
- self.options = options
-
- def name(self):
- return os.path.basename(self.path)
-
- def pathname(self):
- # for svn modules pathname is just the name of the module as
- # all modules are at the root
- return self.name()
-
- def url(self):
- out = Command("svn info {}".format(self.path), self.options).output_of()
- for line in out.split('\n'):
- if line.startswith("URL:"):
- return line.split()[1].strip()
-
- def repo_root(self):
- out = Command("svn info {}".format(self.path), self.options).output_of()
- for line in out.split('\n'):
- if line.startswith("Repository Root:"):
- root = line.split()[2].strip()
- return "{}/{}".format(root, self.pathname())
-
- @classmethod
- def clone(cls, remote, local, options, recursive=False):
- if recursive:
- svncommand = "svn co %s %s" % (remote, local)
- else:
- svncommand = "svn co -N %s %s" % (remote, local)
- Command("rm -rf %s" % local, options).run_silent()
- Command(svncommand, options).run_fatal()
-
- return SvnRepository(local, options)
-
- @classmethod
- def remote_exists(cls, remote, options):
- return Command ("svn list %s &> /dev/null" % remote , options).run()==0
-
- def tag_exists(self, tagname):
- url = "%s/tags/%s" % (self.repo_root(), tagname)
- return SvnRepository.remote_exists(url, self.options)
-
- def update(self, subdir="", recursive=True, branch=None):
- path = os.path.join(self.path, subdir)
- if recursive:
- svncommand = "svn up %s" % path
- else:
- svncommand = "svn up -N %s" % path
- Command(svncommand, self.options).run_fatal()
-
- def commit(self, logfile):
- # add all new files to the repository
- Command("svn status %s | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs svn add" %
- self.path, self.options).output_of()
- Command("svn commit -F %s %s" % (logfile, self.path), self.options).run_fatal()
-
- def to_branch(self, branch):
- remote = "%s/branches/%s" % (self.repo_root(), branch)
- SvnRepository.clone(remote, self.path, self.options, recursive=True)
-
- def to_tag(self, tag):
- remote = "%s/tags/%s" % (self.repo_root(), branch)
- SvnRepository.clone(remote, self.path, self.options, recursive=True)
-
- def tag(self, tagname, logfile):
- tag_url = "%s/tags/%s" % (self.repo_root(), tagname)
- self_url = self.url()
- Command("svn copy -F %s %s %s" % (logfile, self_url, tag_url), self.options).run_fatal()
-
- def diff(self, f=""):
- if f:
- f = os.path.join(self.path, f)
- else:
- f = self.path
- return Command("svn diff %s" % f, self.options).output_of(True)
-
- def diff_with_tag(self, tagname):
- tag_url = "%s/tags/%s" % (self.repo_root(), tagname)
- return Command("svn diff %s %s" % (tag_url, self.url()),
- self.options).output_of(True)
-
- def revert(self, f=""):
- if f:
- Command("svn revert %s" % os.path.join(self.path, f), self.options).run_fatal()
- else:
- # revert all
- Command("svn revert %s -R" % self.path, self.options).run_fatal()
- Command("svn status %s | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs rm -rf " %
- self.path, self.options).run_silent()
-
- def is_clean(self):
- command="svn status %s" % self.path
- return len(Command(command,self.options).output_of(True)) == 0
-
- def is_valid(self):
- return os.path.exists(os.path.join(self.path, ".svn"))
-