-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMygrane.py
executable file
·104 lines (92 loc) · 3.78 KB
/
Mygrane.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python3
# Main controller for a mygrane instance
import argparse
import configparser
import mygrane
import mygrane.collection
def main():
parser = argparse.ArgumentParser(description='Comic Library Manager')
parser.add_argument("-l", help="Directory where comics are stored")
parser.add_argument("--config", help="directory for config files")
parser.add_argument("--initdb", help="Initialize a database in the default directory")
parser.add_argument("--db", help="Alternate database location", type=str)
parser.add_argument("--importdir", help="Import all comics in a specified import directory (recursive)")
parser.add_argument("--mv", help="flag move all comics to specified directory", type=str)
parser.add_argument("--format", help="Specify format for names")
print("Starting instance of Mygrane")
args = parser.parse_args()
# Load information from config filename if not specified as arguments
lib_loc = None
library = None
# Init variables like db location
db = "./database.sqlite"
if args.db:
db = args.db
# Run selected command
if args.initdb:
pass
# Run a loop of asking for commands and running them.
end = False
while (not end):
try:
userinput = input("> ")
cmd = userinput.lower().split(" ")[0]
if cmd == "help":
print("""
Available commands:
quit Quits Mygrane
init <path> Initializes Library at path
test Runs a sort in "Test mode" where it does not move any files. Use "print" to see the result.
sort Sorts library, not allowing duplicates
sortdupes Sorts library, allowing duplicates
sortdelete Sorts library, deleting duplicates
print Prints library contents
""")
elif cmd == "init":
try:
path = " ".join(userinput.split(" ")[1:])
if path != "":
lib_loc = path
except Exception:
# Path not provided, assume one is already provided
pass
if lib_loc is None:
raise Exception("No Library provided")
print("Opening library at location: " + lib_loc)
library = mygrane.collection.Collection(lib_loc)
elif cmd in ["print", "ls"]:
if library is None:
raise Exception("No Library provided")
print(library)
elif cmd in ["sort"]:
if library is None:
raise Exception("No Library provided")
try:
library.sort(test=False, allow_duplicates="False")
except Exception as detail:
print(detail)
elif cmd in ["test"]:
if library is None:
raise Exception("No Library provided")
try:
library.sort(test=True, allow_duplicates="False")
except Exception as detail:
print(detail)
elif cmd in ["sortdupes"]:
if library is None:
raise Exception("No Library provided")
try:
library.sort(test=False, allow_duplicates="True")
except Exception as detail:
print(detail)
elif cmd in ["sortdelete"]:
if library is None:
raise Exception("No Library provided")
try:
library.sort(test=False, allow_duplicates="Delete")
except Exception as detail:
print(detail)
except Exception as detail:
print(detail)
if __name__ == "__main__":
main()