From faf0ad5bcab05b74ee0bfd5a3534c47d66889eca Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Apr 2017 21:53:11 +0300 Subject: refactor: Combine versio.* finding methods --- bumper | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/bumper b/bumper index b2b6ad4..9528bf5 100755 --- a/bumper +++ b/bumper @@ -39,17 +39,17 @@ class Bumper(cliapp.Application): 'New version {} is older than current version {}'.format( version, current_version)) - version_py = self.find_version_py() + version_py = self.find_version_file('version.py') if version_py: print '... {}'.format(version_py) self.write_version_py(version_py, version, '') - version_txt = self.find_version_txt() + version_txt = self.find_version_file('version.txt') if version_txt: print '... {}'.format(version_txt) self.write_version_txt(version_txt, version, '') - version_yaml = self.find_version_yaml() + version_yaml = self.find_version_file('version.yaml') if version_yaml: print '... {}'.format(version_yaml) self.write_version_yaml(version_yaml, version, '') @@ -99,35 +99,18 @@ class Bumper(cliapp.Application): raise cliapp.AppException('Need exactly one argument, the version') return args[0] - def find_version_py(self): + def find_version_file(self, basename): output = cliapp.runcmd(['git', 'ls-files']) filenames = [x.strip() for x in output.splitlines()] - version_pys = [x for x in filenames if x.endswith('/version.py')] - if len(version_pys) == 0: - raise cliapp.AppException('No version.py in project') - elif len(version_pys) > 1: - raise cliapp.AppException('Too many version.py in project') - return version_pys[0] - - def find_version_txt(self): - output = cliapp.runcmd(['git', 'ls-files']) - filenames = [x.strip() for x in output.splitlines()] - version_txts = [x for x in filenames if x == 'version.txt'] - if len(version_txts) == 0: - raise cliapp.AppException('No version.txt in project') - elif len(version_txts) > 1: - raise cliapp.AppException('Too many version.txt in project') - return version_txts[0] - - def find_version_yaml(self): - output = cliapp.runcmd(['git', 'ls-files']) - filenames = [x.strip() for x in output.splitlines()] - version_yamls = [x for x in filenames if x == 'version.yaml'] - if len(version_yamls) == 0: - raise cliapp.AppException('No version.yaml in project') - elif len(version_yamls) > 1: - raise cliapp.AppException('Too many version.yaml in project') - return version_yamls[0] + version_files = [ + x for x in filenames + if x == basename or x.endswith('/' + basename) + ] + if len(version_files) == 0: + raise cliapp.AppException('No {} in project'.format(basename)) + elif len(version_files) > 1: + raise cliapp.AppException('Too many {} in project'.format(basename)) + return version_files[0] def get_current_version(self): return cliapp.runcmd(['python', 'setup.py', '--version']).strip() -- cgit v1.2.1