This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
env.py
98 lines (71 loc) · 2.71 KB
/
env.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
#!python3
import shutil
import os
import console
import blackmamba.ide.bookmark as bookmark
_ROOT_FOLDER = os.path.expanduser('~/Documents/site-packages-3/blackmamba')
_BACKUP_FOLDER = os.path.expanduser('~/Documents/site-packages-3/bm-pip-backup')
def switch_to_working_copy():
print('Switching Black Mamba to Working Copy version')
git_folder = None
paths = bookmark.get_bookmark_paths()
if paths:
for path in paths:
if os.path.basename(path) == 'blackmamba':
git_folder = path
break
if not git_folder:
print('Unable to find blackmamba folder in External files...')
return
git_module_folder = os.path.join(git_folder, 'blackmamba')
if not os.path.isdir(_ROOT_FOLDER):
print('Failed, folder does not exist: {}'.format(_ROOT_FOLDER))
return
if not os.path.isdir(git_folder):
print('Failed, checkout Black Mamba to: {}'.format(git_folder))
return
if os.path.isdir(_BACKUP_FOLDER):
print('Failed, backup folder exists: {}'.format(_BACKUP_FOLDER))
return
shutil.move(_ROOT_FOLDER, _BACKUP_FOLDER)
if os.path.isdir(_ROOT_FOLDER):
print('Failed, folder still exists: {}'.format(_ROOT_FOLDER))
return
os.symlink(git_module_folder, _ROOT_FOLDER)
if not os.path.islink(_ROOT_FOLDER):
print('Failed, folder is not a symlink: {}'.format(_ROOT_FOLDER))
return
print('Black Mamba switched to Working Copy version')
def switch_to_installer():
print('Switching Black Mamba to installer version')
if not os.path.islink(_ROOT_FOLDER):
print('Failed, folder is not a symlink: {}'.format(_ROOT_FOLDER))
return
if not os.path.isdir(_BACKUP_FOLDER):
print('Failed, PIP backup folder does not exist: {}'.format(_BACKUP_FOLDER))
return
os.remove(_ROOT_FOLDER)
shutil.move(_BACKUP_FOLDER, _ROOT_FOLDER)
if not os.path.isdir(_ROOT_FOLDER):
print('Failed, folder does not exists: {}'.format(_ROOT_FOLDER))
return
if os.path.isdir(_BACKUP_FOLDER):
print('Failed, backup folder still does exist: {}'.format(_BACKUP_FOLDER))
return
print('Black Mamba switched to installer version')
def toggle():
try:
if os.path.islink(_ROOT_FOLDER):
console.alert('Black Mamba',
'Switch to installer version?',
'OK')
switch_to_installer()
else:
console.alert('Black Mamba',
'Switch to Working Copy version?',
'OK')
switch_to_working_copy()
except Exception:
pass
if __name__ == '__main__':
toggle()