Refactoring, Removal of most global vars, config default path is ~/ucloud/

This commit is contained in:
ahmadbilalkhalid 2019-12-22 12:26:48 +05:00
commit 04993e4106
23 changed files with 673 additions and 726 deletions

View file

@ -8,8 +8,8 @@ import sys
from uuid import uuid4
from . import logger
from ucloud.config import config, etcd_client
from ucloud.settings import settings
from ucloud.shared import shared
def getxattr(file, attr):
"""Get specified user extended attribute (arg:attr) of a file (arg:file)"""
@ -69,11 +69,10 @@ except Exception as e:
def main():
BASE_DIR = config['storage']['file_dir']
FILE_PREFIX = config['etcd']['file_prefix']
base_dir = settings['storage']['file_dir']
# Recursively Get All Files and Folder below BASE_DIR
files = glob.glob("{}/**".format(BASE_DIR), recursive=True)
files = glob.glob("{}/**".format(base_dir), recursive=True)
# Retain only Files
files = list(filter(os.path.isfile, files))
@ -89,7 +88,7 @@ def main():
file_id = uuid4()
# Get Username
owner = pathlib.Path(file).parts[len(pathlib.Path(BASE_DIR).parts)]
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
@ -105,7 +104,7 @@ def main():
file_path = pathlib.Path(file).parts[-1]
# Create Entry
entry_key = os.path.join(FILE_PREFIX, str(file_id))
entry_key = os.path.join(settings['etcd']['file_prefix'], str(file_id))
entry_value = {
"filename": file_path,
"owner": owner,
@ -115,8 +114,8 @@ def main():
}
logger.info("Tracking %s", file)
# Insert Entry
etcd_client.put(entry_key, entry_value, value_in_json=True)
shared.etcd_client.put(entry_key, entry_value, value_in_json=True)
setxattr(file, "utracked", True)