|
|
@@ -20,6 +20,7 @@ import hashlib |
|
|
|
import io |
|
|
|
import itertools |
|
|
|
import json |
|
|
|
import magic |
|
|
|
import os.path |
|
|
|
import pathlib |
|
|
|
import pasn1 |
|
|
@@ -670,7 +671,7 @@ 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) if not |
|
|
|
created_by_ref) for x in sorted(os.listdir(_dir)) if not |
|
|
|
os.path.isdir(os.path.join(_dir, x)) ] |
|
|
|
|
|
|
|
def get_objstore(options): |
|
|
@@ -820,6 +821,26 @@ def cmd_dump(options): |
|
|
|
for i in objstr: |
|
|
|
print(i.encode('json')) |
|
|
|
|
|
|
|
def cmd_auto(options): |
|
|
|
for i in options.files: |
|
|
|
mf = magic.detect_from_filename(i) |
|
|
|
|
|
|
|
primary = mf[0].split('/', 1)[0] |
|
|
|
mt = mf[0] |
|
|
|
if primary == 'text': |
|
|
|
mt += '; charset=%s' % mf[1] |
|
|
|
|
|
|
|
print('Set:') |
|
|
|
print('\tmimetype:\t%s' % mt) |
|
|
|
print() |
|
|
|
print('Apply (y/N)?') |
|
|
|
|
|
|
|
inp = sys.stdin.readline() |
|
|
|
|
|
|
|
if inp.strip().lower() in ('y', 'yes'): |
|
|
|
options.modtagvalues = [ '+mimetype=%s' % mt ] |
|
|
|
cmd_modify(options) |
|
|
|
|
|
|
|
def cmd_list(options): |
|
|
|
persona, objstr = get_objstore(options) |
|
|
|
|
|
|
@@ -837,7 +858,6 @@ def cmd_list(options): |
|
|
|
except (FileNotFoundError, KeyError) as e: |
|
|
|
print('ERROR: file not found: %s' % repr(i), file=sys.stderr) |
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
except FileNotFoundError: |
|
|
|
# XXX - tell the difference? |
|
|
|
print('ERROR: file not found: %s' % repr(i), |
|
|
@@ -912,6 +932,11 @@ def main(): |
|
|
|
help='files to modify') |
|
|
|
parser_mod.set_defaults(func=cmd_modify) |
|
|
|
|
|
|
|
parser_auto = subparsers.add_parser('auto', help='automatic detection of file properties') |
|
|
|
parser_auto.add_argument('files', nargs='+', |
|
|
|
help='files to modify') |
|
|
|
parser_auto.set_defaults(func=cmd_auto) |
|
|
|
|
|
|
|
parser_list = subparsers.add_parser('list', help='list tags on file(s)') |
|
|
|
parser_list.add_argument('files', nargs='+', |
|
|
|
help='files to modify') |
|
|
@@ -1141,7 +1166,7 @@ class _TestCases(unittest.TestCase): |
|
|
|
|
|
|
|
def test_enumeratedir(self): |
|
|
|
files = enumeratedir(self.tempdir, self.created_by_ref) |
|
|
|
ftest = files[1] |
|
|
|
ftest = [ x for x in files if x.filename == 'test.txt' ][0] |
|
|
|
fname = 'test.txt' |
|
|
|
|
|
|
|
# make sure that they are of type MDBase |
|
|
@@ -1459,6 +1484,7 @@ class _TestCases(unittest.TestCase): |
|
|
|
self.assertRegex(stdout.getvalue(), outre) |
|
|
|
else: |
|
|
|
self.assertEqual(stdout.getvalue(), cmd.get('stdout', '')) |
|
|
|
|
|
|
|
self.assertEqual(stderr.getvalue(), cmd.get('stderr', '')) |
|
|
|
|
|
|
|
self.assertEqual(cm.exception.code, cmd.get('exit', 0)) |
|
|
@@ -1468,9 +1494,13 @@ class _TestCases(unittest.TestCase): |
|
|
|
i.stop() |
|
|
|
|
|
|
|
def test_cmds(self): |
|
|
|
cmds = self.fixtures.glob('cmd.*.json') |
|
|
|
cmds = sorted(self.fixtures.glob('cmd.*.json')) |
|
|
|
|
|
|
|
for i in cmds: |
|
|
|
# make sure each file starts with a clean slate |
|
|
|
self.tearDown() |
|
|
|
self.setUp() |
|
|
|
|
|
|
|
os.chdir(self.tempdir) |
|
|
|
self.run_command_file(i) |
|
|
|
|
|
|
|