-
Notifications
You must be signed in to change notification settings - Fork 4
/
gitsynchista.py
108 lines (79 loc) · 2.68 KB
/
gitsynchista.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
# coding: utf-8
# This file is part of https://github.com/marcus67/gitsynchista
import sys
import os
import console
import six
import log
import config
import sync_config
import sync
import sync_selector
import working_copy
if six.PY3:
from importlib import reload
reload(log)
reload(config)
reload(sync_config)
reload(sync)
reload(sync_selector)
reload(working_copy)
#Use this switch to temporarily disable support for app "working copy"
ENABLE_WORKING_COPY_SUPPORT = True
def load_config_file_and_sync(config_filename):
global logger
config_handler = config.ConfigHandler(sync_config.SyncConfig())
tool_sync_config = config_handler.read_config_file(config_filename)
sync_tool = sync.SyncTool(tool_sync_config)
try:
sync_tool.scan()
except Exception as e:
logger.exception("Exception during scan: %s" % str(e))
return
try:
sync_tool.sync()
except Exception as e:
logger.exception("Exception during sync: %s" % str(e))
def wakeup_webdav_server(config):
working_copy_support = working_copy.WorkingCopySupport()
working_copy_support.wakeup_webdav_server()
def start_gui(check_wakeup):
global logger
console.show_activity("Scanning repositories...")
if check_wakeup:
logger.info("Checking if wakeup is required...")
sync_tools = []
configs = sync.find_sync_configs()
working_copy_configs = []
working_copy_configs.extend(filter(lambda config:config.repository.working_copy_wakeup, configs))
working_copy_active = ENABLE_WORKING_COPY_SUPPORT and len(working_copy_configs) > 0
if working_copy_active and check_wakeup:
wakeup_webdav_server(working_copy_configs[0])
logger.info("Exiting to await callback from Working Copy...")
console.hide_activity()
return
logger.info("Starting GUI...")
for config in configs:
logger.info("Found configuration '%s'..." % config.repository.name)
try:
sync_tool = sync.SyncTool(config)
sync_tools.append(sync_tool)
except Exception as e:
logger.exception("Error '%s' while processing configuration '%s'" % ( str(e), config.repository.name) )
selector = sync_selector.SyncSelector()
console.hide_activity()
selector.select(sync_tools, working_copy_active=working_copy_active)
def main():
global logger
logger = log.open_logging('gitsynchista', True)
logger.info('Starting gitsynchista')
if len(sys.argv) == 2:
if (sys.argv[1].startswith(working_copy.PARAM_IGNORE_WAKEUP)):
start_gui(False)
else:
load_config_file_and_sync(sys.argv[1])
else:
start_gui(ENABLE_WORKING_COPY_SUPPORT)
logger.info('Terminating gitsynchista')
if __name__ == '__main__':
main()