|
|
@@ -9,6 +9,8 @@ from cryptography.hazmat.primitives.serialization import Encoding, \ |
|
|
|
|
|
|
|
from unittest import mock |
|
|
|
|
|
|
|
from .hostid import hostuuid |
|
|
|
|
|
|
|
import base58 |
|
|
|
import copy |
|
|
|
import datetime |
|
|
@@ -542,15 +544,16 @@ class FileObject(MDBase): |
|
|
|
|
|
|
|
fname = os.path.realpath(fname) |
|
|
|
return uuid.uuid5(_NAMESPACE_MEDASHARE_PATH, |
|
|
|
'/'.join(os.path.split(fname))) |
|
|
|
str(hostuuid()) + '/'.join(os.path.split(fname))) |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def from_file(cls, filename, created_by_ref): |
|
|
|
s = os.stat(filename) |
|
|
|
# XXX - add host uuid? |
|
|
|
obj = { |
|
|
|
'dir': os.path.dirname(filename), |
|
|
|
'created_by_ref': created_by_ref, |
|
|
|
'hostid': hostuuid(), |
|
|
|
'dir': os.path.dirname(filename), |
|
|
|
'filename': os.path.basename(filename), |
|
|
|
'id': cls.make_id(filename), |
|
|
|
'mtime': datetime.datetime.fromtimestamp(s.st_mtime, |
|
|
@@ -582,7 +585,8 @@ def enumeratedir(_dir, created_by_ref): |
|
|
|
Returned is a list of FileObjects.''' |
|
|
|
|
|
|
|
return [FileObject.from_file(os.path.join(_dir, x), |
|
|
|
created_by_ref) for x in os.listdir(_dir)] |
|
|
|
created_by_ref) for x in os.listdir(_dir) if not |
|
|
|
os.path.isdir(os.path.join(_dir, x)) ] |
|
|
|
|
|
|
|
def get_objstore(options): |
|
|
|
persona = get_persona(options) |
|
|
@@ -723,7 +727,7 @@ def cmd_list(options): |
|
|
|
objstr.loadobj(fobj) |
|
|
|
|
|
|
|
objs = objstr.by_file(i) |
|
|
|
except (FileNotFoundError, KeyError): |
|
|
|
except (FileNotFoundError, KeyError) as e: |
|
|
|
print('ERROR: file not found: %s' % repr(i), file=sys.stderr) |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
@@ -734,7 +738,6 @@ def cmd_list(options): |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
for j in objstr.by_file(i): |
|
|
|
#print >>sys.stderr, `j._obj` |
|
|
|
for k, v in _iterdictlist(j): |
|
|
|
print('%s:\t%s' % (k, v)) |
|
|
|
|
|
|
@@ -933,7 +936,7 @@ class _TestCases(unittest.TestCase): |
|
|
|
self.assertEqual(ftest.dir, str(self.tempdir)) |
|
|
|
# XXX - do we add host information? |
|
|
|
self.assertEqual(ftest.id, uuid.uuid5(_NAMESPACE_MEDASHARE_PATH, |
|
|
|
'/'.join(os.path.split(self.tempdir) + |
|
|
|
str(hostuuid()) + '/'.join(os.path.split(self.tempdir) + |
|
|
|
( fname, )))) |
|
|
|
self.assertEqual(ftest.mtime, datetime.datetime(2019, 5, 20, |
|
|
|
21, 47, 36, tzinfo=datetime.timezone.utc)) |
|
|
@@ -1171,6 +1174,8 @@ class _TestCases(unittest.TestCase): |
|
|
|
testfname = os.path.join(self.tempdir, 'test.txt') |
|
|
|
newtestfname = os.path.join(self.tempdir, 'newfile.txt') |
|
|
|
|
|
|
|
patches = [] |
|
|
|
|
|
|
|
for cmd in cmds: |
|
|
|
try: |
|
|
|
special = cmd['special'] |
|
|
@@ -1187,6 +1192,10 @@ class _TestCases(unittest.TestCase): |
|
|
|
pasn1obj = pasn1.loads(fp.read()) |
|
|
|
objcnt = len(pasn1obj['objects']) |
|
|
|
self.assertEqual(objcnt, cmd['count']) |
|
|
|
elif special == 'set hostid': |
|
|
|
hostidpatch = mock.patch(__name__ + '.hostuuid') |
|
|
|
hostidpatch.start().return_value = uuid.uuid4() |
|
|
|
patches.append(hostidpatch) |
|
|
|
else: # pragma: no cover |
|
|
|
raise ValueError('unhandled special: %s' % repr(special)) |
|
|
|
|
|
|
@@ -1216,6 +1225,10 @@ class _TestCases(unittest.TestCase): |
|
|
|
|
|
|
|
self.assertEqual(cm.exception.code, cmd.get('exit', 0)) |
|
|
|
|
|
|
|
patches.reverse() |
|
|
|
for i in patches: |
|
|
|
i.stop() |
|
|
|
|
|
|
|
def test_cmds(self): |
|
|
|
cmds = self.fixtures.glob('cmd.*.json') |
|
|
|
|
|
|
|