diff --git a/PKG-INFO b/PKG-INFO index 09b7a5e..ed9b954 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.core -Version: 0.0.1 +Version: 0.0.2 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/PKG-INFO b/swh.core.egg-info/PKG-INFO similarity index 94% copy from PKG-INFO copy to swh.core.egg-info/PKG-INFO index 09b7a5e..ed9b954 100644 --- a/PKG-INFO +++ b/swh.core.egg-info/PKG-INFO @@ -1,10 +1,10 @@ Metadata-Version: 1.0 Name: swh.core -Version: 0.0.1 +Version: 0.0.2 Summary: Software Heritage core utilities Home-page: https://forge.softwareheritage.org/diffusion/DCORE/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN diff --git a/swh.core.egg-info/SOURCES.txt b/swh.core.egg-info/SOURCES.txt new file mode 100644 index 0000000..edcd3a1 --- /dev/null +++ b/swh.core.egg-info/SOURCES.txt @@ -0,0 +1,21 @@ +.gitignore +MANIFEST.in +Makefile +requirements.txt +setup.py +version.txt +bin/swh-hashdir +bin/swh-hashfile +swh.core.egg-info/PKG-INFO +swh.core.egg-info/SOURCES.txt +swh.core.egg-info/dependency_links.txt +swh.core.egg-info/requires.txt +swh.core.egg-info/top_level.txt +swh/core/config.py +swh/core/hashutil.py +swh/core/json.py +swh/core/scheduling.py +swh/core/tests/test_config.py +swh/core/tests/test_hashutil.py +swh/core/tests/test_json.py +swh/core/tests/test_scheduling.py \ No newline at end of file diff --git a/swh.core.egg-info/dependency_links.txt b/swh.core.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/swh.core.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/swh.core.egg-info/requires.txt b/swh.core.egg-info/requires.txt new file mode 100644 index 0000000..dbaf71c --- /dev/null +++ b/swh.core.egg-info/requires.txt @@ -0,0 +1,3 @@ +celery +python-dateutil +vcversioner diff --git a/swh.core.egg-info/top_level.txt b/swh.core.egg-info/top_level.txt new file mode 100644 index 0000000..0cb0f8f --- /dev/null +++ b/swh.core.egg-info/top_level.txt @@ -0,0 +1 @@ +swh diff --git a/swh/core/config.py b/swh/core/config.py index 768ecc1..09df18c 100644 --- a/swh/core/config.py +++ b/swh/core/config.py @@ -1,55 +1,57 @@ # Copyright (C) 2015 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import configparser import os # conversion per type _map_convert_fn = { 'int': int, 'bool': lambda x: x.lower() == 'true', + 'list[str]': lambda x: [value.strip() for value in x.split(',')], + 'list[int]': lambda x: [int(value.strip()) for value in x.split(',')], } def read(conf_file, default_conf=None): """Read the user's configuration file. Fill in the gap using `default_conf`. `default_conf` is similar to this: DEFAULT_CONF = { 'a': ('string', '/tmp/swh-loader-git/log'), 'b': ('string', 'dbname=swhloadergit') 'c': ('bool', true) 'e': ('bool', None) 'd': ('int', 10) } """ config = configparser.ConfigParser(defaults=default_conf) config.read(os.path.expanduser(conf_file)) conf = config._sections['main'] # remaining missing default configuration key are set # also type conversion is enforced for underneath layer for key in default_conf: nature_type, default_value = default_conf[key] val = conf.get(key, None) if not val: # fallback to default value conf[key] = default_value else: # value present but in string format, force type conversion conf[key] = _map_convert_fn.get(nature_type, lambda x: x)(val) return conf def prepare_folders(conf, *keys): """Prepare the folder mentioned in config under keys. """ def makedir(folder): if not os.path.exists(folder): os.makedirs(folder) for key in keys: makedir(conf[key]) diff --git a/swh/core/tests/test_config.py b/swh/core/tests/test_config.py index 0b0bb73..abd2028 100644 --- a/swh/core/tests/test_config.py +++ b/swh/core/tests/test_config.py @@ -1,78 +1,94 @@ # Copyright (C) 2015 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import tempfile import unittest import os import shutil from nose.tools import istest from swh.core import config class ConfReaderTest(unittest.TestCase): @classmethod - def setUp(self): + def setUp(cls): # create a temporary folder - self.tmpdir = tempfile.mkdtemp(prefix='test-swh-core.') - self.conffile = os.path.join(self.tmpdir, 'config.ini') - with open(self.conffile, 'w') as conf: + cls.tmpdir = tempfile.mkdtemp(prefix='test-swh-core.') + cls.conffile = os.path.join(cls.tmpdir, 'config.ini') + with open(cls.conffile, 'w') as conf: conf.write("""[main] a = 1 b = this is a string c = true +ls = list, of, strings +li = 1, 2, 3, 4 """) @classmethod - def tearDown(self): - shutil.rmtree(self.tmpdir) + def tearDown(cls): + shutil.rmtree(cls.tmpdir) @istest def read(self): # given - default_conf = {'a': ('int', 2), - 'b': ('string', 'default-string'), - 'c': ('bool', True), - 'd': ('int', 10)} + default_conf = { + 'a': ('int', 2), + 'b': ('string', 'default-string'), + 'c': ('bool', True), + 'd': ('int', 10), + 'e': ('int', None), + 'f': ('bool', None), + 'g': ('string', None), + 'ls': ('list[str]', ['a', 'b', 'c']), + 'li': ('list[int]', [42, 43]), + } # when res = config.read(self.conffile, default_conf) # then - self.assertEquals(res, {'a': 1, - 'b': 'this is a string', - 'c': True, - 'd': 10}) + self.assertEquals(res, { + 'a': 1, + 'b': 'this is a string', + 'c': True, + 'd': 10, + 'e': None, + 'f': None, + 'g': None, + 'ls': ['list', 'of', 'strings'], + 'li': [1, 2, 3, 4], + }) @istest def prepare_folder(self): # given conf = {'path1': os.path.join(self.tmpdir, 'path1'), 'path2': os.path.join(self.tmpdir, 'path2', 'depth1')} # the folders does not exists self.assertFalse(os.path.exists(conf['path1']), "path1 should not exist.") self.assertFalse(os.path.exists(conf['path2']), "path2 should not exist.") # when config.prepare_folders(conf, 'path1') # path1 exists but not path2 self.assertTrue(os.path.exists(conf['path1']), "path1 should now exist!") self.assertFalse(os.path.exists(conf['path2']), "path2 should not exist.") # path1 already exists, skips it but creates path2 config.prepare_folders(conf, 'path1', 'path2') self.assertTrue(os.path.exists(conf['path1']), "path1 should still exist!") self.assertTrue(os.path.exists(conf['path2']), "path2 should now exist.") diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..8bd4e22 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v0.0.2-0-g2475f30 \ No newline at end of file