-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·136 lines (107 loc) · 4.65 KB
/
setup
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python
import argparse, os, re, sys
GITHUB_DESCRIPTION = re.compile('repository-description">(.*)<')
ERROR_NOT_RUN = -1
ERROR_USER_ABORTED = -2
ERROR_UNKNOWN = -3
INSTALLATION_ABORTED = 'Installation aborted.'
if __name__ != '__main__':
print "You must simply run the installation script."
exit(ERROR_NOT_RUN)
WHIZBANG = os.path.dirname(os.path.realpath(__file__))
MODULES = os.path.sep.join((WHIZBANG, 'modules'))
GLOYDIUS = os.path.sep.join((MODULES, 'gloydius'))
HOME = os.path.expanduser('~')
SHEBANG = '#!/bin/sh\n'
ZSHEBANG = '#!/bin/zsh\n'
def install_file(source, target): symlink(os.path.sep.join((HOME, target)), os.path.sep.join((WHIZBANG, 'conf', source)), BACKUP)
def ini_config(ini, changes):
sections = {}
for name, params in changes.iteritems(): sections[name.join(('[', ']'))] = params
ini_config(os.path.sep.join((HOME, ini)), sections, BACKUP)
def activate():
hook = p(WHIZBANG, 'conf', 'hook')
shell = os.path.basename(os.environ['SHELL'])
def install_hooks(resource, hooks, source):
name = p(HOME, resource)
print '{} -> {}'.format(name, hooks)
write_file(name, ''.join((('. ' if source else ''), hook, ' ', shell, ' ', hooks, '\n')))
if shell == 'zsh':
pass
for resource, hooks in [
('.zshenv', 'shell'),
('.zprofile', 'shell-early-login'),
('.zshrc', 'shell-interactive'),
('.zlogin', 'shell-late-login'),
('.zlogout', 'shell-logout'),
]: install_hooks(resource, hooks, True)
kde4hooks = [
('.kde/env', 'de-pre-startup'),
('.kde/Autostart', 'de-startup'),
('.kde/shutdown', 'de-shutdown')
]
kde5hooks = [
('.config/plasma-workspace/env', 'de-pre-startup'),
('.config/autostart', 'de-startup'),
('.config/plasma-workspace/shutdown', 'de-shutdown')
]
de_hooks = kde5hooks
for resource, hooks in de_hooks: install_hooks(p(resource, hooks + '.sh'), hooks, False)
os.system(WHIZBANG + '/conf/prompt-generator')
def deactivate():
print "NOT IMPLEMENTED YET"
def print_description(module):
print module['type']
def load_modules_list():
modules = {}
for name in find_in(MODULES_LIST, 'file not link'):
modules[name] = module = {}
for line in read_file_lines(p(MODULES_LIST, name)):
line = line.strip()
eq = line.find('=')
if eq == -1 or line.startswith('#'): continue
module[line[:eq]] = line[eq + 1:]
return modules
def list_modules():
modules = load_modules_list()
installed = find_in(MODULES, 'not hidden dir')
for name in installed | set(modules.keys()):
print name #find_on_page('https://github.com/{}'.format('robbyrussell/oh-my-zsh'), GITHUB_DESCRIPTION).strip()
try:
if not os.path.isdir(GLOYDIUS):
os.makedirs(GLOYDIUS)
print 'Whizbang requires Gloydius python libraries to work. Would you like to download it now? (yes/no)'
while True:
answer = raw_input().lower()
if answer == 'no':
print INSTALLATION_ABORTED
exit(ERROR_USER_ABORTED)
if answer != 'yes':
print "Please just type 'yes' or 'no'"
continue
code = os.system('cd {}; git clone https://github.com/Grief/gloydius.git'.format(MODULES))
if code != 0:
print 'Cloning from git failed with error {}. You may check the above output. {}'.format(code, INSTALLATION_ABORTED)
exit(ERROR_UNKNOWN)
break
sys.path.insert(0, GLOYDIUS)
from gloydius.install import *
from gloydius.fs import path as p
from gloydius.web import *
MODULES_LIST = p(MODULES, '.list')
parser = argparse.ArgumentParser()
actions = parser.add_mutually_exclusive_group()
actions.add_argument('-a', '--activate', action='store_true', help='Activates Whizbang for the current user')
actions.add_argument('-d', '--deactivate', action='store_true', help='Deactivates Whizbang for the current user')
actions.add_argument('-l', '--list-modules', action='store_true', help='List modules')
args = parser.parse_args()
if args.activate: activate()
elif args.deactivate: deactivate()
elif args.list_modules: list_modules()
BACKUP = p(WHIZBANG, 'backup') # None for disabling backing up
# install_file('conky.conf', '.conkyrc')
#
# install_file('hook', '.config/autostart/de-startup')
#
# ini_config('.kde/share/config/kdeglobals', {'Paths': {'Autostart[$e]': '/g/components/kde/autostart'}})
except KeyboardInterrupt: print INSTALLATION_ABORTED