|
|
@@ -19,7 +19,7 @@ if False: |
|
|
|
logging.getLogger('sqlalchemy').addHandler(_handler) |
|
|
|
logging.getLogger('sqlalchemy.engine').setLevel(lvl) |
|
|
|
|
|
|
|
from .utils import _debprint |
|
|
|
from .utils import _debprint, enable_debug, disable_debug |
|
|
|
|
|
|
|
def _getquery(q, objstr): |
|
|
|
return repr(str(q.compile(objstr._engine, |
|
|
@@ -841,6 +841,7 @@ class FileObject(MDBase): |
|
|
|
#print(repr(self), repr(s), s.st_mtime, file=_real_stderr) |
|
|
|
if self.mtime.timestamp() != mtimets or \ |
|
|
|
self.size != s.st_size: |
|
|
|
_debprint('times:', self.mtime.timestamp(), mtimets) |
|
|
|
raise ValueError('file %s has changed' % |
|
|
|
repr(self.filename)) |
|
|
|
|
|
|
@@ -1029,7 +1030,10 @@ def cmd_modify(options, persona, objstr, cache): |
|
|
|
try: |
|
|
|
key, v = k |
|
|
|
except ValueError: |
|
|
|
del obj[k[0]] |
|
|
|
try: |
|
|
|
del obj[k[0]] |
|
|
|
except KeyError: |
|
|
|
pass |
|
|
|
else: |
|
|
|
obj[key].remove(v) |
|
|
|
|
|
|
@@ -1206,6 +1210,18 @@ def checkforfile(objstr, curfile, ask=False): |
|
|
|
|
|
|
|
return fobj |
|
|
|
|
|
|
|
from contextlib import contextmanager |
|
|
|
import time |
|
|
|
|
|
|
|
@contextmanager |
|
|
|
def timeblock(tag): |
|
|
|
s = time.time() |
|
|
|
try: |
|
|
|
yield |
|
|
|
finally: |
|
|
|
e = time.time() |
|
|
|
_debprint(tag, e - s) |
|
|
|
|
|
|
|
@init_datastructs |
|
|
|
def cmd_interactive(options, persona, objstr, cache): |
|
|
|
files = [ pathlib.Path(x) for x in options.files ] |
|
|
@@ -1219,33 +1235,36 @@ def cmd_interactive(options, persona, objstr, cache): |
|
|
|
files = sorted(pathlib.Path('.').iterdir()) |
|
|
|
|
|
|
|
while True: |
|
|
|
curfile = files[idx] |
|
|
|
with timeblock('checkfile'): |
|
|
|
curfile = files[idx] |
|
|
|
|
|
|
|
fobj = checkforfile(objstr, curfile, not autoskip) |
|
|
|
fobj = checkforfile(objstr, curfile, not autoskip) |
|
|
|
#_debprint(repr(fobj)) |
|
|
|
|
|
|
|
if fobj is None and autoskip and idx > 0 and idx < len(files) - 1: |
|
|
|
# if we are auto skipping, and within range, continue |
|
|
|
if inp == '1': |
|
|
|
idx = max(0, idx - 1) |
|
|
|
continue |
|
|
|
if inp == '2': |
|
|
|
idx = min(len(files) - 1, idx + 1) |
|
|
|
continue |
|
|
|
if fobj is None and autoskip and idx > 0 and idx < len(files) - 1: |
|
|
|
# if we are auto skipping, and within range, continue |
|
|
|
if inp == '1': |
|
|
|
idx = max(0, idx - 1) |
|
|
|
continue |
|
|
|
if inp == '2': |
|
|
|
idx = min(len(files) - 1, idx + 1) |
|
|
|
continue |
|
|
|
|
|
|
|
print('Current: %s' % repr(str(curfile))) |
|
|
|
|
|
|
|
if fobj is None: |
|
|
|
print('No file object for this file.') |
|
|
|
else: |
|
|
|
try: |
|
|
|
objs = objstr.by_file(curfile) |
|
|
|
except KeyError: |
|
|
|
print('No tags or metadata object for this file.') |
|
|
|
with timeblock('byfile'): |
|
|
|
if fobj is None: |
|
|
|
print('No file object for this file.') |
|
|
|
else: |
|
|
|
for k, v in _iterdictlist(objs[0]): |
|
|
|
if k in { 'sig', 'hashes' }: |
|
|
|
continue |
|
|
|
print('%s:\t%s' % (k, v)) |
|
|
|
try: |
|
|
|
objs = objstr.by_file(curfile) |
|
|
|
except KeyError: |
|
|
|
print('No tags or metadata object for this file.') |
|
|
|
else: |
|
|
|
for k, v in _iterdictlist(objs[0]): |
|
|
|
if k in { 'sig', 'hashes' }: |
|
|
|
continue |
|
|
|
print('%s:\t%s' % (k, v)) |
|
|
|
|
|
|
|
if idx == 0: |
|
|
|
print('1) No previous file') |
|
|
@@ -1356,7 +1375,7 @@ def cmd_dump(options, persona, objstr, cache): |
|
|
|
print(i.encode('json')) |
|
|
|
|
|
|
|
def cmd_auto(options): |
|
|
|
for i in options.files: |
|
|
|
for i in options.files[:]: |
|
|
|
mf = detect_from_filename(i) |
|
|
|
|
|
|
|
primary = mf[0].split('/', 1)[0] |
|
|
@@ -1372,7 +1391,8 @@ def cmd_auto(options): |
|
|
|
inp = sys.stdin.readline() |
|
|
|
|
|
|
|
if inp.strip().lower() in ('y', 'yes'): |
|
|
|
options.modtagvalues = [ '+mimetype=%s' % mt ] |
|
|
|
options.modtagvalues = [ '-mimetype', '+mimetype=%s' % mt ] |
|
|
|
options.files = [ i ] |
|
|
|
cmd_modify(options) |
|
|
|
|
|
|
|
@init_datastructs |
|
|
@@ -1668,6 +1688,9 @@ def main(): |
|
|
|
|
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
|
|
|
|
parser.add_argument('--debug', action='store_true', |
|
|
|
default=False, help='enable debug output') |
|
|
|
|
|
|
|
parser.add_argument('--db', '-d', type=str, |
|
|
|
help='base name for storage') |
|
|
|
|
|
|
@@ -1762,6 +1785,11 @@ def main(): |
|
|
|
|
|
|
|
options = parser.parse_args() |
|
|
|
|
|
|
|
if options.debug: |
|
|
|
enable_debug() |
|
|
|
else: |
|
|
|
disable_debug() |
|
|
|
|
|
|
|
try: |
|
|
|
fun = options.func |
|
|
|
except AttributeError: |
|
|
|