From a56b852dc5017eef652ea2e3e684ebdb284af1ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20R=2E=20Sede=C3=B1o?= Date: Fri, 25 Sep 2009 14:54:20 -0400 Subject: [PATCH] Polish version bump to 0.9 parse command line arguments --- git-svn-keywords.py | 77 +++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/git-svn-keywords.py b/git-svn-keywords.py index d1e6f21..4f08171 100755 --- a/git-svn-keywords.py +++ b/git-svn-keywords.py @@ -26,19 +26,21 @@ # git svn keyword parsing, populating, and clearing. from __future__ import with_statement -import ConfigParser, errno, os, re, urllib +import errno, os, re, urllib +from ConfigParser import ConfigParser +from optparse import OptionParser import git -VERSION = 0 +VERSION = "0.9" # Where we keep data in the repo. def gsk(g): return os.path.join(g.path, 'svn_keywords') #Configuration Data -CONFIG = ConfigParser.ConfigParser() -FILES = ConfigParser.ConfigParser() -FILEINFO = ConfigParser.ConfigParser() +CONFIG = ConfigParser() +FILES = ConfigParser() +FILEINFO = ConfigParser() CONFIG_PATH = '' FILES_PATH = '' @@ -73,7 +75,7 @@ def parse_svn_unhandled(g): ver = -1 if CONFIG.has_option('core', 'version'): - ver = CONFIG.getint('core', 'version') + ver = CONFIG.get('core', 'version') lastrev = None if ver == VERSION: @@ -155,7 +157,7 @@ def get_path_info(g, path): return info_dict # Do the work. -def smudge(g, clean=False): +def smudge(g, options): parse_svn_unhandled(g) rev_head = int(g.git.svn('find-rev', 'HEAD')) url_base = g.git.svn('info', '--url') @@ -172,7 +174,7 @@ def smudge(g, clean=False): kw_rev = max(filter(lambda x: x <= rev_head, map(int, FILES.options(path)))) info_dict = {} - if not clean: + if not options.clean: info_dict.update(get_path_info(g, path)) info_dict['URL'] = '/'.join([url_base, path]) info_dict['Name'] = os.path.basename(path) @@ -186,7 +188,7 @@ def smudge(g, clean=False): for k in keywords: for sk in svn_keywords: if k in svn_keywords[sk]: - if clean: + if options.clean: buf = re.sub(get_svn_keyword_re(sk), '$\\1$', buf) elif sk == 'Id': id_str = ' '.join([info_dict['Name'], @@ -199,27 +201,40 @@ def smudge(g, clean=False): with open(os.path.join(g.wd, path), 'w') as f: f.write(buf) - - #print path + ' [' + ', '.join(keywords) + '] [len: ' + str(len(buf)) +']' - -def clean(g): - smudge(g,True) + if options.verbose: + print path + ' [' + ', '.join(keywords) + '] [len: ' + str(len(buf)) +']' if __name__ == '__main__': - try: - g = git.Repo() - except git.errors.InvalidGitRepositoryError: - print "You are not in a git repository or working directory." - exit(1) - - CONFIG_PATH = os.path.join(gsk(g), 'conf.ini') - FILES_PATH = os.path.join(gsk(g), 'files.ini') - FILEINFO_PATH = os.path.join(gsk(g), 'fileinfo.ini') - - CONFIG.read(CONFIG_PATH) - for section in ['core','CommitToRev','BlobToCommit', 'RevInfo']: - if not CONFIG.has_section(section): - CONFIG.add_section(section) - - smudge(g) - #clean(g) + + parser = OptionParser(version="%prog "+str(VERSION)) + parser.set_defaults(clean=None) + parser.add_option("-s", "--smudge", + action="store_false", dest="clean", + help="Populate svn:keywords.") + parser.add_option("-c", "--clean", + action="store_true", dest="clean", + help="Return svn:keywords to pristene state.") + parser.add_option("-v", "--verbose", + action="store_true", dest="verbose", default=False) + (options, args) = parser.parse_args() + + if (options.clean is None): + parser.print_help() + exit(0) + else: + try: + g = git.Repo() + except git.errors.InvalidGitRepositoryError: + print "You are not in a git repository or working directory." + exit(1) + + CONFIG_PATH = os.path.join(gsk(g), 'conf.ini') + FILES_PATH = os.path.join(gsk(g), 'files.ini') + FILEINFO_PATH = os.path.join(gsk(g), 'fileinfo.ini') + + CONFIG.read(CONFIG_PATH) + for section in ['core','CommitToRev','BlobToCommit', 'RevInfo']: + if not CONFIG.has_section(section): + CONFIG.add_section(section) + + smudge(g, options) -- 2.45.2