From 09814aae2119aa80632a8d5e8f06b35a63a41153 Mon Sep 17 00:00:00 2001 From: Yosuke Mizutani Date: Sun, 11 Jan 2015 23:39:24 +0900 Subject: [PATCH 1/5] fix sys.path priority --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 34c241f..b51ca90 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def get_version(): import sys - sys.path.append(SRC_DIR) + sys.path[:0] = [SRC_DIR] return __import__('artifactcli').__version__ From eda2c53d784cffb3914a8d9fd56065365e170602 Mon Sep 17 00:00:00 2001 From: Yosuke Mizutani Date: Wed, 14 Jan 2015 00:09:22 +0900 Subject: [PATCH 2/5] fix timing of new line in the progress bar --- src/artifactcli/util/progressbar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/artifactcli/util/progressbar.py b/src/artifactcli/util/progressbar.py index 3e22eda..7d9ac56 100644 --- a/src/artifactcli/util/progressbar.py +++ b/src/artifactcli/util/progressbar.py @@ -31,6 +31,8 @@ def stop(self): """ self.__stop_event.set() self.thread.join() + self.fp.write('\n') + self.fp.flush() # check thread's exceptions if not self.ex_queue.empty(): @@ -56,7 +58,6 @@ def __target(self): self.fp.write('.') self.fp.flush() event.wait(self.interval) - self.fp.write('\n') def __enter__(self): return self From 69731cc846aed578a7b2375e8b270aebcef5accd Mon Sep 17 00:00:00 2001 From: Yosuke Mizutani Date: Wed, 14 Jan 2015 00:10:13 +0900 Subject: [PATCH 3/5] bump up to version 0.1.6 --- src/artifactcli/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/artifactcli/__init__.py b/src/artifactcli/__init__.py index 1276d02..0a8da88 100644 --- a/src/artifactcli/__init__.py +++ b/src/artifactcli/__init__.py @@ -1 +1 @@ -__version__ = "0.1.5" +__version__ = "0.1.6" From 61977af0efba4d53aee0f5a78e605b1b8ee9fc9e Mon Sep 17 00:00:00 2001 From: Yosuke Mizutani Date: Wed, 14 Jan 2015 00:18:24 +0900 Subject: [PATCH 4/5] remove git assertions of real files --- tests/artifactcli/artifact/test_artifact.py | 1 - tests/artifactcli/artifact/test_gitinfo.py | 1 - tests/artifactcli/operation/test_upload.py | 1 - tests/artifactcli/test_repository.py | 1 - 4 files changed, 4 deletions(-) diff --git a/tests/artifactcli/artifact/test_artifact.py b/tests/artifactcli/artifact/test_artifact.py index a30f3e7..003c320 100644 --- a/tests/artifactcli/artifact/test_artifact.py +++ b/tests/artifactcli/artifact/test_artifact.py @@ -103,7 +103,6 @@ def test_from_path(self): ret = Artifact.from_path('GROUP_ID', 'tests/resources/test-artifact-1.2.3.dat') self.assertEqual(ret.basic_info, BasicInfo('GROUP_ID', 'test-artifact', '1.2.3', 'dat', None)) self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563')) - self.assertFalse(ret.scm_info is None) def test_dict_conversions(self): self.assertEqual(Artifact.from_dict(self.test_data[0].to_dict()), self.test_data[0]) diff --git a/tests/artifactcli/artifact/test_gitinfo.py b/tests/artifactcli/artifact/test_gitinfo.py index 19c9534..b81bc00 100644 --- a/tests/artifactcli/artifact/test_gitinfo.py +++ b/tests/artifactcli/artifact/test_gitinfo.py @@ -63,7 +63,6 @@ def test_repr(self): def test_from_path(self): gi = GitInfo.from_path('tests/resources/test-artifact-1.2.3.dat') - self.assertFalse(gi is None) def test_from_path_error(self): self.assertEqual(GitInfo.from_path('tests/resources/test001_no_such_path.dat'), None) diff --git a/tests/artifactcli/operation/test_upload.py b/tests/artifactcli/operation/test_upload.py index 0eab379..1ee41e6 100644 --- a/tests/artifactcli/operation/test_upload.py +++ b/tests/artifactcli/operation/test_upload.py @@ -29,4 +29,3 @@ def test_run(self): ret = r.artifacts['test-artifact'][1] self.assertEqual(ret.basic_info, BasicInfo('com.github.mogproject', 'test-artifact', '1.2.3', 'dat', 2)) self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563')) - self.assertFalse(ret.scm_info is None) diff --git a/tests/artifactcli/test_repository.py b/tests/artifactcli/test_repository.py index 2e55158..787def2 100644 --- a/tests/artifactcli/test_repository.py +++ b/tests/artifactcli/test_repository.py @@ -167,7 +167,6 @@ def test_upload_file_real_file(self): ret = r.artifacts['test-artifact'][0] self.assertEqual(ret.basic_info, BasicInfo('com.github.mogproject', 'test-artifact', '1.2.3', 'dat', 1)) self.assertEqual((ret.file_info.size, ret.file_info.md5), (11, '7a38cb250db7127113e00ad5e241d563')) - self.assertFalse(ret.scm_info is None) def test_upload_file_force(self): expected = [Artifact(BasicInfo('com.github.mogproject', 'art-test', '0.0.1', 'jar', 1), From 31f158184fe7205b7f000c35deec35f5ea5e2d0e Mon Sep 17 00:00:00 2001 From: Yosuke Mizutani Date: Wed, 14 Jan 2015 00:41:15 +0900 Subject: [PATCH 5/5] refactor --debug option parsing --- src/artifactcli/argparser.py | 5 +++-- src/artifactcli/settings.py | 20 ++++++++++---------- tests/artifactcli/test_settings.py | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/artifactcli/argparser.py b/src/artifactcli/argparser.py index c920fe9..39f404a 100644 --- a/src/artifactcli/argparser.py +++ b/src/artifactcli/argparser.py @@ -1,4 +1,5 @@ from optparse import OptionParser +import logging VERSION = 'artifact-cli %s' % __import__('artifactcli').__version__ USAGE = """ @@ -56,7 +57,7 @@ def get_parser(): help='Amazon S3 region name (default: us-east-1)' ) parser.add_option( - '--debug', action='store_true', dest='debug', default=False, - help='enables debug level logging' + '--debug', action='store_const', dest='log_level', const=logging.DEBUG, default=logging.INFO, + help='set log level to DEBUG' ) return parser diff --git a/src/artifactcli/settings.py b/src/artifactcli/settings.py index ce44fa7..9c68fe8 100644 --- a/src/artifactcli/settings.py +++ b/src/artifactcli/settings.py @@ -14,14 +14,13 @@ class Settings(CaseClass): """ parser = argparser.get_parser() - def __init__(self, log_level=logging.INFO, operation=None, options=None, repo=None): - super(Settings, self).__init__(['log_level', 'operation', 'options', 'repo']) + def __init__(self, operation=None, options=None, repo=None): + super(Settings, self).__init__(['operation', 'options', 'repo']) # fallback operation operation = operation or HelpOperation(self.parser) # set parameters - self.log_level = logging.DEBUG if options and options['debug'] else log_level self.operation = operation self.repo = repo self.options = options @@ -30,7 +29,8 @@ def configure_logging(self): """ Setup logging settings """ - logging.basicConfig(level=self.log_level, format='[%(levelname)s] %(message)s') + level = self.options.log_level if self.options else logging.INFO + logging.basicConfig(level=level, format='[%(levelname)s] %(message)s') return self def parse_args(self, argv): @@ -47,19 +47,19 @@ def parse_args(self, argv): except AssertionError: return self - return Settings(self.log_level, operation, opt_dict, self.repo) + return Settings(operation, opt_dict, self.repo) def load_config(self): """ Load configuration file and set repo """ if self.options is None: - return Settings(self.log_level) + return Settings() group_id = self.operation.group_id if not group_id: logging.error('Failed to load config: group id is not set in operation') - return Settings(self.log_level) + return Settings() access_key = self.options['access_key'] secret_key = self.options['secret_key'] @@ -80,7 +80,7 @@ def load_config(self): region = r if region is None else region except IOError: logging.error('Failed to open configuration file: %s' % config) - return Settings(self.log_level) + return Settings() for x, arg, opt in [ (access_key, 'access_key', '--access'), @@ -90,12 +90,12 @@ def load_config(self): if x is None: logging.error('Oops! "%s" setting is missing.' % arg) logging.error('Use "%s" option or write configuration file: %s' % (opt, config)) - return Settings(self.log_level) + return Settings() # set repository driver driver = S3Driver(access_key, secret_key, bucket, group_id, region) repo = Repository(driver, group_id) - return Settings(self.log_level, self.operation, self.options, repo) + return Settings(self.operation, self.options, repo) @classmethod def _read_aws_config(cls, fp, group_id): diff --git a/tests/artifactcli/test_settings.py b/tests/artifactcli/test_settings.py index 9214fea..9417127 100644 --- a/tests/artifactcli/test_settings.py +++ b/tests/artifactcli/test_settings.py @@ -11,10 +11,12 @@ class TestSettings(unittest.TestCase): def setUp(self): - self.default_opts = {'access_key': None, 'force': False, 'bucket': None, 'region': None, 'debug': False, - 'print_only': False, 'secret_key': None, 'config': '~/.artifact-cli', 'output': None} - self.full_opts = {'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', 'region': None, 'debug': True, - 'print_only': True, 'secret_key': 'SECRET_KEY', 'config': 'xxx', 'output': None} + self.default_opts = {'access_key': None, 'force': False, 'bucket': None, 'region': None, + 'log_level': logging.INFO, 'print_only': False, 'secret_key': None, + 'config': '~/.artifact-cli', 'output': None} + self.full_opts = {'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', 'region': None, + 'log_level': logging.DEBUG, 'print_only': True, 'secret_key': 'SECRET_KEY', + 'config': 'xxx', 'output': None} def _updated_opts(self, updates): d = copy(self.default_opts) @@ -23,7 +25,6 @@ def _updated_opts(self, updates): def test_parse_args_empty(self): self.assertEqual(Settings().parse_args(['art']), Settings()) - self.assertEqual(Settings().log_level, logging.INFO) def test_parse_args_list(self): s = Settings().parse_args(['art', 'list', 'gid']) @@ -34,7 +35,6 @@ def test_parse_args_list_full(self): ['art', 'list', 'gid', '--config', 'xxx', '--check', '--force', '--access', 'ACCESS_KEY', '--secret', 'SECRET_KEY', '--bucket', 'BUCKET', '--debug']) self.assertEqual(s, Settings(operation=ListOperation('gid', []), options=self.full_opts)) - self.assertEqual(s.log_level, logging.DEBUG) def test_parse_args_list_error(self): self.assertEqual(Settings().parse_args(['art', 'list']), Settings()) @@ -102,23 +102,23 @@ def test_parse_args_info_full(self): o = self._updated_opts({ 'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', 'print_only': True, 'secret_key': 'SECRET_KEY', 'config': 'xxx', - 'output': 'text', 'debug': True}) + 'output': 'text', 'log_level': logging.DEBUG}) self.assertEqual(s, Settings(operation=InfoOperation('gid', ['xxx', '123'], 'text'), options=o)) s = Settings().parse_args( ['art', 'info', 'gid', 'xxx', 'latest', '--config', 'xxx', '--check', '--force', '--access', 'ACCESS_KEY', '--secret', 'SECRET_KEY', '--bucket', 'BUCKET', '--debug']) o = self._updated_opts({ - 'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', - 'print_only': True, 'secret_key': 'SECRET_KEY', 'config': 'xxx', 'output': None, 'debug': True}) + 'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', 'print_only': True, + 'secret_key': 'SECRET_KEY', 'config': 'xxx', 'output': None, 'log_level': logging.DEBUG}) self.assertEqual(s, Settings(operation=InfoOperation('gid', ['xxx', 'latest'], None), options=o)) s = Settings().parse_args( ['art', 'info', 'gid', 'xxx', 'latest', '--config', 'xxx', '--check', '--force', '--access', 'ACCESS_KEY', '--secret', 'SECRET_KEY', '--bucket', 'BUCKET', '--output', 'json', '--debug']) o = self._updated_opts({ - 'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', - 'print_only': True, 'secret_key': 'SECRET_KEY', 'config': 'xxx', 'output': 'json', 'debug': True}) + 'access_key': 'ACCESS_KEY', 'force': True, 'bucket': 'BUCKET', 'print_only': True, + 'secret_key': 'SECRET_KEY', 'config': 'xxx', 'output': 'json', 'log_level': logging.DEBUG}) self.assertEqual(s, Settings(operation=InfoOperation('gid', ['xxx', 'latest'], 'json'), options=o)) def test_parse_args_info_error(self):