forked from WeAreAVP/fixity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
112 lines (91 loc) · 3.52 KB
/
Main.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
105
106
107
108
109
110
111
112
# -*- coding: UTF-8 -*-
'''
Created on May 14, 2014
@author: Furqan Wasi <[email protected]>
'''
from os import path
from Core import SharedApp, DatabaseLockHandler
from GUI import GUILibraries
import App
from argparse import ArgumentParser
import sys, os, traceback, logging
sys.path.append('/usr/local/lib/python2.7')
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/local/lib/python2.7/site-packages/PySide')
class Main (object):
def __init__(self, is_unit_test = False):
SharedApp.SharedApp.App = App.App.getInstance(is_unit_test)
self.Fixity = SharedApp.SharedApp.App
self.Fixity.is_unit_test = is_unit_test
def LaunchGUI(self, arg):
app = GUILibraries.QApplication(arg)
app.MainFixityWindow = App.ProjectGUI.ProjectGUI()
app.MainFixityWindow.show()
app.exec_()
def LaunchCLI(self, project_name, called_from = 'CLI', new_path=None):
is_lock_exists = False
is_dead_lock = False
try:
process_id = os.getpid()
except:
process_id = None
pass
# Get File Locker and check for dead lock
try:
lock = DatabaseLockHandler.DatabaseLockHandler(self.Fixity.Configuration.getLockFilePath(),process_id, timeout=20)
is_dead_lock = lock.isProcessLockFileIsDead()
except:
self.Fixity.logger.LogException(Exception.message)
print(Exception.message)
pass
try:
if is_dead_lock:
lock.is_locked = True
lock.release()
except:
self.Fixity.logger.LogException(Exception.message)
pass
try:
is_lock_exists = lock.isLockFileExists()
except:
pass
project_core = self.Fixity.ProjectRepo.getSingleProject(project_name)
if is_lock_exists is False:
if new_path is not None:
dir_information = {}
dir_information['path'] = new_path
self.Fixity.Database.update(self.Fixity.Database._tableProjectPath, dir_information, '1 = 1')
for dirs_objects in project_core.directories:
project_core.directories[dirs_objects].setPath(new_path)
break
project_core.Save(False)
if called_from == 'test':
return project_core.Run(False, False, False, 'test')
else:
project_core.Run()
else:
print('Fixity is already scanning a project.\nPlease wait until the current scan completes before starting a new one.')
return ''
def log_uncaught_exceptions(ex_cls, ex, tb):
logging.critical(''.join(traceback.format_tb(tb)))
logging.critical('{0}: {1}'.format(ex_cls, ex))
if __name__ == '__main__':
try:
parser = ArgumentParser()
parser.add_argument('-a', '--autorun')
args = parser.parse_args()
except:
pass
# sys.excepthook = log_uncaught_exceptions
# If Received argument (project name and run command), it with run the
# scheduler other wise it will open Fixity Front end View)
Fixity = Main(False)
if args.autorun is None or args.autorun == '':
Fixity.LaunchGUI(sys.argv)
else:
try:
Fixity.LaunchCLI(args.autorun)
except:
exc_type, exc_obj, exc_tb = sys.exc_info()
file_name = path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print("Could not run this Project "+str(Exception.message))