示例#1
0
 def setUp(self):
     self.path = tempfile.mkdtemp(prefix='test_file_archive_')
     FileStore.create_store(self.path)
     self.store = FileStore(self.path)
     testfiles = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'testfiles')
     self.t = lambda f: os.path.join(testfiles, f)
示例#2
0
def initialize():
    if configuration.check('file_store'):
        file_store_path = configuration.file_store
    else:
        file_store_path = os.path.join(current_dot_vistrails(), 'file_archive')
    if not os.path.exists(file_store_path) or not os.listdir(file_store_path):
        FileStore.create_store(file_store_path)
    set_default_store(FileStore(file_store_path))
示例#3
0
def main(args):
    warnings.filterwarnings('always', category=UsageWarning)

    usage = _(
        "usage: {bin} <store> create\n"
        "   or: {bin} <store> add <filename> [key1=value1] [...]\n"
        "   or: {bin} <store> write [key1=value1] [...]\n"
        "   or: {bin} <store> query [-d] [-t] [key1=value1] [...]\n"
        "   or: {bin} <store> print [-m] [-t] <filehash> [...]\n"
        "   or: {bin} <store> print [-m] [-t] [key1=value1] [...]\n"
        "   or: {bin} <store> remove [-f] <filehash>\n"
        "   or: {bin} <store> remove [-f] <key1=value1> [...]\n"
        "   or: {bin} <store> verify\n"
        "   or: {bin} <store> view\n",
        bin='file_archive')

    if len(args) < 2:
        sys.stderr.write(usage)
        sys.exit(1)

    store = args[0]
    command = args[1]

    if command == 'create':
        try:
            FileStore.create_store(store)
        except Exception as e:
            sys.stderr.write(_("Can't create store: {err}\n", err=e.args[0]))
            sys.exit(3)
        sys.exit(0)

    try:
        store = FileStore(store)
    except Exception as e:
        sys.stderr.write(_("Invalid store: {err}\n", err=e.args[0]))
        sys.exit(3)

    try:
        try:
            func = commands[command]
        except KeyError:
            sys.stderr.write(usage)
            sys.exit(1)
        try:
            func(store, args[2:])
        except Exception:
            import traceback
            traceback.print_exc()
            sys.exit(3)
    finally:
        store.close()

    sys.exit(0)
示例#4
0
def main(args):
    warnings.filterwarnings('always', category=UsageWarning)

    usage = _(
        "usage: {bin} <store> create\n"
        "   or: {bin} <store> add <filename> [key1=value1] [...]\n"
        "   or: {bin} <store> write [key1=value1] [...]\n"
        "   or: {bin} <store> query [-d] [-t] [key1=value1] [...]\n"
        "   or: {bin} <store> print [-m] [-t] <filehash> [...]\n"
        "   or: {bin} <store> print [-m] [-t] [key1=value1] [...]\n"
        "   or: {bin} <store> remove [-f] <filehash>\n"
        "   or: {bin} <store> remove [-f] <key1=value1> [...]\n"
        "   or: {bin} <store> verify\n"
        "   or: {bin} <store> view\n",
        bin='file_archive')

    if len(args) < 2:
        sys.stderr.write(usage)
        sys.exit(1)

    store = args[0]
    command = args[1]

    if command == 'create':
        try:
            FileStore.create_store(store)
        except Exception as e:
            sys.stderr.write(_("Can't create store: {err}\n", err=e.args[0]))
            sys.exit(3)
        sys.exit(0)

    try:
        store = FileStore(store)
    except Exception as e:
        sys.stderr.write(_("Invalid store: {err}\n", err=e.args[0]))
        sys.exit(3)

    try:
        try:
            func = commands[command]
        except KeyError:
            sys.stderr.write(usage)
            sys.exit(1)
        try:
            func(store, args[2:])
        except Exception:
            import traceback
            traceback.print_exc()
            sys.exit(3)
    finally:
        store.close()

    sys.exit(0)
示例#5
0
class TestStore(unittest.TestCase):
    """Tests opening the store and using it.
    """
    def setUp(self):
        self.path = tempfile.mkdtemp(prefix='test_file_archive_')
        FileStore.create_store(self.path)
        self.store = FileStore(self.path)
        testfiles = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 'testfiles')
        self.t = lambda f: os.path.join(testfiles, f)

    def tearDown(self):
        self.store.close()
        self.store = None
        shutil.rmtree(self.path)

    def test_req_empty(self):
        out = []
        self.assertEqual(run_program(self.path, 'query', out=out), 0)
        self.assertEqual(out, [])

    def test_putfile(self):
        out = []
        self.assertEqual(
            run_program(self.path, 'add', self.t('file1.bin'), 'a=b',
                        out=out),
            0)
        h1 = 'fce92fa2647153f7d696a3c1884d732290273102'
        o1 = '8ce67dc4c67401ff8122ecebc98ecee506211f88'
        self.assertEqual(out, [o1])
        self.assertTrue(os.path.isfile(os.path.join(
            self.path,
            'objects',
            'fc',
            'e92fa2647153f7d696a3c1884d732290273102')))
        self.assertEqual(
            self.store.get(o1).metadata,
            {'hash': h1, 'a': 'b'})

    def test_wrongpath(self):
        self.assertEqual(run_program(self.path, 'add', 'nonexistentpath-fa'),
                         1)

    def test_query(self):
        self.store.add_file(self.t('file1.bin'), {'tag': 'test', 'test': 1})
        self.store.add_file(self.t('file2.bin'), {'tag': 'other', 'test': 2})

        def r(*args):
            out = []
            self.assertEqual(run_program(self.path, *args, out=out), 0)
            return out

        h1 = 'fce92fa2647153f7d696a3c1884d732290273102'
        o1 = '2da501fcdc9630dc96edaf03a31d9b5088d7ebe2'
        h2 = 'de0ccf54a9c1de0d9fdbf23f71a64762448057d0'
        o2 = '51a43b0dd01fa86de710150b5e4dac56ebe9f58c'

        out = r('query', 'tag=test')
        m = [o1,
             '\t%s\t%s' % ('hash', h1),
             '\t%s\t%s' % ('tag', 'test'),
             '\t%s\t%s' % ('test', '1')]
        self.assertEqual(out, m)

        out = r('query', '-d')
        self.assertEqual(eval('\n'.join(out)), {
            o1: {'hash': h1, 'tag': 'test', 'test': 1},
            o2: {'hash': h2, 'tag': 'other', 'test': 2},
        })
        self.assertEqual(out,
                         ['{',
                          '    "%s": {' % o1,
                          '        "hash": "%s",' % h1,
                          '        "tag": "test",',
                          '        "test": 1',
                          '    },',
                          '    "%s": {' % o2,
                          '        "hash": "%s",' % h2,
                          '        "tag": "other",',
                          '        "test": 2',
                          '    }',
                          '}'])