index folder for easier shell operation

This commit is contained in:
Ville Rantanen
2020-12-11 11:11:04 +02:00
parent fa4335abc7
commit 1e57071ad7

22
flit.py
View File

@@ -99,9 +99,23 @@ def random_char():
def random_name():
chars = [random_char() for x in range(6)]
chars.insert(3, '-')
return ''.join(chars)
while True:
existing_names = get_folder_names()
index = 0
for existing in existing_names:
try:
e_index = int(existing[0:3])
index = max(e_index + 1, index)
except:
pass
name = "{:03d}-{}-{}".format(
index,
"".join([random_char() for x in range(3)]),
"".join([random_char() for x in range(3)])
)
if not os.path.exists(name):
break
return name
def create_new(p, days, description):
@@ -210,8 +224,6 @@ if __name__ == '__main__':
os.chdir(os.path.dirname(__file__))
if opts.command == 'add':
new_name = random_name()
while os.path.exists(new_name):
new_name = random_name()
create_new(new_name, opts.days, opts.description)
print(os.path.abspath(new_name))
print("")