cleaning out old stuff

This commit is contained in:
Ville Rantanen
2020-12-28 23:17:32 +02:00
parent 906f6fd457
commit 572107bfe2

52
flit.py
View File

@@ -134,57 +134,39 @@ def copy_files(cwd, new_name, files):
for f in opts.files:
print(f"Copying: {f}")
source = os.path.join(cwd, f)
if source.endswith("/"):
source = source[0:-1]
base = os.path.basename(source)
if not os.path.exists(source):
print("Path does not exist")
continue
if os.path.isfile(source):
shutil.copy2(source, target)
else:
shutil.copytree(
source,
os.path.join(target, f),
os.path.join(target, base),
symlinks=True,
)
# def get_description(f):
# try:
# with open(f) as fp:
# return "".join(filter(lambda x: x in string.printable, fp.read(32).split("\n")[0]))
# except:
# return "-"
def get_stats(p):
# TODO: named tuple
config = read_config(p)
if config is None:
with open(os.path.join(p, DEL_TIME), "rt") as fp:
do_del = int(fp.read(64))
desc = get_description(os.path.join(p, DESCRIPTION))
now = datetime.now()
mtime = datetime.fromtimestamp(os.path.getmtime(os.path.join(p, DEL_TIME)))
del_delta = timedelta(days=do_del)
del_time = mtime + del_delta
to_del_time = del_time - now
is_due = now > del_time
config = {}
config["description"] = desc
config["delete_time"] = del_time
config["created"] = mtime
else:
desc = config["description"]
del_time = datetime.fromisoformat(config["delete_time"])
now = datetime.now()
mtime = datetime.fromisoformat(config["created"])
to_del_time = del_time - now
is_due = now > del_time
del_time = datetime.fromisoformat(config["delete_time"])
now = datetime.now()
mtime = datetime.fromisoformat(config["created"])
to_del_time = del_time - now
is_due = now > del_time
config["delete_time"] = del_time
config["created"] = mtime
config["name"] = p
config["to_deletion"] = to_del_time
config["due"] = is_due
# mtime, del_time, to_del_time, is_due, desc
# write_config(p, config)
return config
@@ -225,7 +207,6 @@ def list_folders(root_folder, verbose=False, filter_name=None):
sub_files = get_sub_files(c["name"])
for sp in sub_files:
print(" {}/{}/{}".format(root_folder, c["name"], quote(sp, "/")))
# print(p, stats, sub_files)
def del_due_folders():
@@ -237,11 +218,8 @@ def del_due_folders():
def read_config(p):
try:
with open(os.path.join(p, CONFIG), "rt") as fp:
return json.load(fp)
except:
return None
with open(os.path.join(p, CONFIG), "rt") as fp:
return json.load(fp)
def write_config(p, config):