diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 38ff52a..5980a7c 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -693,10 +693,32 @@ class FileObject(MDBase): return uuid.uuid5(_NAMESPACE_MEDASHARE_PATH, str(hostid) + '/'.join(os.path.split(fname))) + _statsymbtoname = { getattr(stat, x): 'stat.' + x for x in dir(stat) if x.startswith('S_') } + + @classmethod + def _modetosymbolic(cls, mode): # pragma: no cover + r = [] + while mode: + nbit = -mode & mode + + r.append(cls._statsymbtoname[nbit]) + + mode = mode & ~nbit + + return '|'.join(r) + @classmethod + def _real_stat_repr(cls, st): # pragma: no cover + return 'os.stat_result' \ + '((%s, %d, %d, %d, %d, %d, %d, %d, %.6f, %d))' % \ + (cls._modetosymbolic(st.st_mode), 10, 100, 1, 100, 100, + st.st_size, st.st_atime, st.st_mtime, st.st_ctime) + @classmethod def from_file(cls, filename, created_by_ref): filename = os.path.abspath(filename) s = os.stat(filename) + # keep so that when new files are added, it's easy to get stat + #_debprint(repr(filename), cls._real_stat_repr(s)) # XXX - race here, fix w/ checking mtime before/after? obj = { 'created_by_ref': created_by_ref,