Fix issues in naming and few other things
This commit is contained in:
parent
f919719b1e
commit
71279a968f
21 changed files with 274 additions and 281 deletions
|
|
@ -3,6 +3,7 @@ import os
|
|||
import pathlib
|
||||
import subprocess as sp
|
||||
import time
|
||||
import sys
|
||||
from uuid import uuid4
|
||||
|
||||
from . import logger
|
||||
|
|
@ -19,7 +20,6 @@ def getxattr(file, attr):
|
|||
'--absolute-names'], stderr=sp.DEVNULL)
|
||||
value = value.decode("utf-8")
|
||||
except sp.CalledProcessError as e:
|
||||
logger.exception(e)
|
||||
value = None
|
||||
|
||||
return value
|
||||
|
|
@ -63,14 +63,13 @@ try:
|
|||
sp.check_output(['which', 'getfattr'])
|
||||
sp.check_output(['which', 'setfattr'])
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
print('Make sure you have getfattr and setfattr available')
|
||||
exit(1)
|
||||
logger.error("You don't seems to have both getfattr and setfattr")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
BASE_DIR = config['storage']["FILE_DIR"]
|
||||
FILE_PREFIX = config['storage']["FILE_PREFIX"]
|
||||
BASE_DIR = config['storage']['file_dir']
|
||||
FILE_PREFIX = config['etcd']['file_prefix']
|
||||
|
||||
# Recursively Get All Files and Folder below BASE_DIR
|
||||
files = glob.glob("{}/**".format(BASE_DIR), recursive=True)
|
||||
|
|
@ -79,7 +78,7 @@ def main():
|
|||
files = list(filter(os.path.isfile, files))
|
||||
|
||||
untracked_files = list(
|
||||
filter(lambda f: not bool(getxattr(f, "user.utracked")), files)
|
||||
filter(lambda f: not bool(getxattr(f, "utracked")), files)
|
||||
)
|
||||
|
||||
tracked_files = list(
|
||||
|
|
@ -89,7 +88,8 @@ def main():
|
|||
file_id = uuid4()
|
||||
|
||||
# Get Username
|
||||
owner = pathlib.Path(file).parts[3]
|
||||
owner = pathlib.Path(file).parts[len(pathlib.Path(BASE_DIR).parts)]
|
||||
|
||||
# Get Creation Date of File
|
||||
# Here, we are assuming that ctime is creation time
|
||||
# which is mostly not true.
|
||||
|
|
@ -101,9 +101,7 @@ def main():
|
|||
# Compute sha512 sum
|
||||
sha_sum = sha512sum(file)
|
||||
|
||||
# File Path excluding base and username
|
||||
file_path = pathlib.Path(file).parts[4:]
|
||||
file_path = os.path.join(*file_path)
|
||||
file_path = pathlib.Path(file).parts[-1]
|
||||
|
||||
# Create Entry
|
||||
entry_key = os.path.join(FILE_PREFIX, str(file_id))
|
||||
|
|
@ -115,10 +113,10 @@ def main():
|
|||
"size": size
|
||||
}
|
||||
|
||||
print("Tracking {}".format(file))
|
||||
logger.info("Tracking %s", file)
|
||||
# Insert Entry
|
||||
etcd_client.put(entry_key, entry_value, value_in_json=True)
|
||||
setxattr(file, "user.utracked", True)
|
||||
setxattr(file, "utracked", True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue