-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainApp.py
51 lines (46 loc) · 1.41 KB
/
mainApp.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
'''
@author: anwar
'''
import os
import sys
from Database import Database
from Commands import Commands
def looping(commander):
'''Enter user interactive mode, wait for user's input
'''
while True:
commands = input('> ')
if not commander.processes(commands):
break
print("Goodbye...")
def loadOrCreateDb(dbName):
'''Load database from file or create a new one
'''
db = None
if os.path.exists(dbName):
db = Database.load(dbName)
else:
print("Creat a new database '{0}'".format(dbName))
db = Database(dbName)
return db
def saveDb(db, dbName = "Anwar.DB"):
'''Save current database to local file
'''
db.save(dbName)
if __name__ == "__main__":
print("""File management system V1.0 by Anwar [email protected] & [email protected]
User can provide database name or leave it empty for default name 'Default.db'
If database doesn't exist, new one will be created.
Loop instruction: press ENTER key after you input each line of command.
Use 'quit' to quit the program.
Use 'help' to get more information.
COMMAND arguments - input help for more information
""")
dbfilePath = "Default.db"
# print(sys.argv)
if len(sys.argv) >= 2:
dbfilePath = sys.argv[1]
db = loadOrCreateDb(dbfilePath)
commander = Commands(db)
looping(commander)
saveDb(db, dbfilePath)