-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitSyncApp.py
108 lines (78 loc) · 2.54 KB
/
GitSyncApp.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
import rumps
import yaml
import logging
import os.path
import os
from RumpusGitNotified import RumpusGitNotified
from gitsync.GitSync import GitSync
default_config = {
'targets': {}
}
def get_config():
config = {
'targets': {}
}
user_config_path = os.path.expanduser("~/.GitSync")
if not os.path.isdir(user_config_path):
os.makedirs(user_config_path)
for root, dirs, files in os.walk(user_config_path):
logger.info(files)
for f in files:
(root, ext) = os.path.splitext(f)
if ext == '.yaml':
stream = open(os.path.join(user_config_path, f), 'r')
target = yaml.safe_load(stream)
logger.info(target)
config['targets'][target['name']] = target
return config
class GitSyncApp(rumps.App):
def __init__(self):
super(GitSyncApp, self).__init__("GitSync", icon='MenuIcon.png')
config = get_config()
# None menu items are dividers
menu_items = ["Help", None, ]
self.targets = config['targets']
self.syncs = {}
for name, target in config['targets'].items():
menu_items.append(
rumps.MenuItem(name, callback=self.toggle_sync)
)
menu_items.append(None)
self.menu = menu_items
@rumps.clicked("Help")
def prefs(self, _):
rumps.alert("Talk to Jachin.")
def toggle_sync(self, sender):
sender.state = not sender.state
if not sender.title in self.syncs:
config = self.targets[sender.title]
notifier = RumpusGitNotified()
self.syncs[sender.title] = GitSync(config, notifier)
git_sync = self.syncs[sender.title]
if sender.state:
git_sync.start()
else:
git_sync.stop()
# @rumps.clicked("Silly button")
# def onoff(self, sender):
# sender.state = not sender.state
# @rumps.clicked("Say hi")
# def sayhi(self, _):
# logger.info("hi!")
# rumps.notification(
# "Awesome title",
# "amazing subtitle",
# "hi!!1",
# sound=False
# )
if __name__ == "__main__":
logger = logging.getLogger('GitSyncApp')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
logger.addHandler(ch)
GitSyncApp().run()