-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.py
121 lines (101 loc) · 3.75 KB
/
setup.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
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @brief: ......
# @date: 2023.09.10 14:40:50
import os
import sys
import shutil
os.system("") # Unable to explain this, just for Windows cmd color print
from utils.utils_cmn import CmnUtils
from utils.utils_logger import LoggerUtils
from utils.utils_file import FileUtils
from utils.utils_import import ImportUtils
g_this_file = os.path.realpath(sys.argv[0])
g_this_path = os.path.dirname(g_this_file)
sys.path.append(os.path.dirname(g_this_path))
g_wing_path = ImportUtils.initEnv(os.path.dirname(g_this_path))
g_bin_path = os.path.expanduser("~") + os.sep + 'bin' # such as: /Users/${username}/bin
# --------------------------------------------------------------------------------------------------------------------------
def createPath(path):
if os.path.isdir(path): return
os.makedirs(path)
if os.path.isdir(path): return
LoggerUtils.e('No access permissions for ' + path)
def doUninstall():
LoggerUtils.println('rm files ...')
try:
ppath = os.path.dirname(g_wing_path)
if os.path.isdir(ppath): FileUtils.remove(ppath)
LoggerUtils.println('rm bin')
if CmnUtils.isOsWindows():
f = g_bin_path + os.sep + 'wing.py'
if os.path.isfile(f): os.remove(f)
f = g_bin_path + os.sep + 'wing.bat'
if os.path.isfile(f): os.remove(f)
else:
f = g_bin_path + os.sep + 'wing'
if os.path.isfile(f): os.remove(f)
except Exception as e:
print(e)
print('\ndone.')
def getWingVer():
with open(g_this_path + os.sep + 'wing.py', 'r') as f:
for line in f.readlines():
line = line.strip()
if CmnUtils.isEmpty(line): continue
if not line.startswith('g_ver'): continue
pos1 = line.find("'")
pos2 = line.rfind("'")
return line[pos1+1:pos2]
return None
def printInfo():
print('\n ' + setup_config['name'])
ver = getWingVer()
if not CmnUtils.isEmpty(ver): print('version: ' + ver)
print(' author: ' + setup_config['author'])
print(' email: ' + setup_config['author_email'])
print(' ' + setup_config['description'])
def doInstall():
createPath(g_bin_path)
LoggerUtils.println('copy files ...')
try:
if os.path.isdir(g_wing_path): FileUtils.remove(g_wing_path)
FileUtils.copyDir(g_this_path, g_wing_path)
if os.path.isdir(g_wing_path + os.sep + '.git'): FileUtils.remove(g_wing_path + os.sep + '.git')
if os.path.isdir(g_wing_path + os.sep + '.idea'): FileUtils.remove(g_wing_path + os.sep + '.idea')
LoggerUtils.println('copy bins ...')
if CmnUtils.isOsWindows():
shutil.copyfile(g_this_path + os.sep + 'wing.py', g_bin_path + os.sep + 'wing.py')
shutil.copyfile(g_this_path + os.sep + 'wing.bat', g_bin_path + os.sep + 'wing.bat')
else:
shutil.copyfile(g_this_path + os.sep + 'wing.py', g_bin_path + os.sep + 'wing')
CmnUtils.doCmd('chmod a+x %s ' % (g_bin_path + os.sep + 'wing'))
printInfo()
LoggerUtils.light('\nAdd to system environment: ' + g_bin_path)
LoggerUtils.light('\n done.')
return
except Exception as e:
print(e)
setup_config = {
'name' :'wing',
'author' :'iofomo',
'author_email' :'[email protected]',
'description' :'Develop tools'
}
def run():
if 1 < len(sys.argv):
if sys.argv[1] == 'install':
doInstall()
return
if sys.argv[1] == 'uninstall':
doUninstall()
return
print(
'''
The most similar command is
install
uninstall
'''
)
if __name__ == "__main__":
run()