cleaning out old stuff
This commit is contained in:
38
flit.py
38
flit.py
@@ -134,43 +134,27 @@ def copy_files(cwd, new_name, files):
|
|||||||
for f in opts.files:
|
for f in opts.files:
|
||||||
print(f"Copying: {f}")
|
print(f"Copying: {f}")
|
||||||
source = os.path.join(cwd, 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):
|
if os.path.isfile(source):
|
||||||
shutil.copy2(source, target)
|
shutil.copy2(source, target)
|
||||||
else:
|
else:
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
source,
|
source,
|
||||||
os.path.join(target, f),
|
os.path.join(target, base),
|
||||||
symlinks=True,
|
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):
|
def get_stats(p):
|
||||||
# TODO: named tuple
|
# TODO: named tuple
|
||||||
config = read_config(p)
|
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"])
|
del_time = datetime.fromisoformat(config["delete_time"])
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
mtime = datetime.fromisoformat(config["created"])
|
mtime = datetime.fromisoformat(config["created"])
|
||||||
@@ -183,8 +167,6 @@ def get_stats(p):
|
|||||||
config["to_deletion"] = to_del_time
|
config["to_deletion"] = to_del_time
|
||||||
config["due"] = is_due
|
config["due"] = is_due
|
||||||
|
|
||||||
# mtime, del_time, to_del_time, is_due, desc
|
|
||||||
# write_config(p, config)
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@@ -225,7 +207,6 @@ def list_folders(root_folder, verbose=False, filter_name=None):
|
|||||||
sub_files = get_sub_files(c["name"])
|
sub_files = get_sub_files(c["name"])
|
||||||
for sp in sub_files:
|
for sp in sub_files:
|
||||||
print(" {}/{}/{}".format(root_folder, c["name"], quote(sp, "/")))
|
print(" {}/{}/{}".format(root_folder, c["name"], quote(sp, "/")))
|
||||||
# print(p, stats, sub_files)
|
|
||||||
|
|
||||||
|
|
||||||
def del_due_folders():
|
def del_due_folders():
|
||||||
@@ -237,11 +218,8 @@ def del_due_folders():
|
|||||||
|
|
||||||
|
|
||||||
def read_config(p):
|
def read_config(p):
|
||||||
try:
|
|
||||||
with open(os.path.join(p, CONFIG), "rt") as fp:
|
with open(os.path.join(p, CONFIG), "rt") as fp:
|
||||||
return json.load(fp)
|
return json.load(fp)
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def write_config(p, config):
|
def write_config(p, config):
|
||||||
|
|||||||
Reference in New Issue
Block a user