From 89e84d11a149696aab37645db0b9c4f50fded1f7 Mon Sep 17 00:00:00 2001 From: Philip Thiem Date: Sun, 30 Jun 2013 00:13:56 -0500 Subject: Added a class for getting SVN information with a cmd. Using XML because the regular output is probably internationalized. Need to inspect setuptools/command/egg_info.py setuptools/command/sdist.py setuptools/package_index.py to see how used again to see if we will every be parsing a raw XML file or if always from .svn/enteries, if so looks like we can just replace the whole of the file parsing. --HG-- extra : rebase_source : 5e10e3b43fbe12f890d09923c1050f8384db7f84 --- setuptools/svn_utils.py | 116 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 16 deletions(-) (limited to 'setuptools/svn_utils.py') diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py index 2a200fdf..ad3b5f15 100644 --- a/setuptools/svn_utils.py +++ b/setuptools/svn_utils.py @@ -1,6 +1,10 @@ import os import re +#requires python >= 2.4 +from subprocess import Popen as _Popen, PIPE as _PIPE + + def get_entries_files(base, recurse=True): for base,dirs,files in os.walk(os.curdir): if '.svn' not in dirs: @@ -12,6 +16,17 @@ def get_entries_files(base, recurse=True): f.close() class SVNEntries(object): + known_svn_versions = { + '1.4.x': 8, + '1.5.x': 9, + '1.6.x': 10, + #11 didn't exist (maybe 1.7-dev) + #12 is the number in the file there is another + #number in .svn/wb.db that is at larger so + #looks like they won't be updating it any longer. + '1.7.x+': 12, + } + def __init__(self, data): self.data = data @@ -26,8 +41,27 @@ class SVNEntries(object): @classmethod def read(class_, file): data = file.read() - is_xml = data.startswith(']*path="(\.+)">', re.I) + entryre = re.compile(r'', re.M or re.I) + urlre = re.compile('(.*?)', re.I) + revre = re.compile(']*revision="(\d+)"', re.I) + namere = re.compile('(.*?)', re.I) + + def __get_cached_dir_data(self): + return self.dir_data + + def __get_cached_entries(self): + return self.entries + + def is_valid(self): + return bool(self.get_dir_data()) + + def get_dir_data(self): + #regard the shell argument, see: http://bugs.python.org/issue8557 + # and http://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path + proc = _Popen(['svn', 'info', '--xml', self.path], + stdout=_PIPE, shell=(sys.platform=='win32')) + data = unicode(proc.communicate()[0], encoding='utf-8') + self.dir_data = self.entryre.findall(data) + self.get_dir_data = self.__get_cached_dir_data + return self.dir_data + + def get_entries(self): + #regard the shell argument, see: http://bugs.python.org/issue8557 + # and http://stackoverflow.com/questions/5658622/python-subprocess-popen-environment-path + proc = _Popen(['svn', 'list', '--xml', self.path], + stdout=_PIPE, shell=(sys.platform=='win32')) + data = unicode(proc.communicate()[0], encoding='utf-8') + self.dir_data = self.entryre.findall(data) + self.get_dir_data = self.__get_cached_dir_data + return self.dir_data + + def get_url(self): + "Get repository URL" + return self.urlre.search(self.get_sections()[0]).group(1) + + def parse_revision_numbers(self): + #NOTE: if one has recently commited, the new revision doesn't get updated until svn update + if not self.is_valid(): + return list() + else: + return [ + int(m.group(1)) + for entry in self.get_enteries() + for m in self.revre.finditer(entry) + ] + + def get_undeleted_records(self): + #NOTE: Need to pars enteries? + if not self.is_valid(): + return list() + else: + return [ + m.group(1)) + for entry in self.get_enteries() + for m in self.namere.finditer(entry) + ] + -- cgit v1.2.1