1 Star 3 Fork 1

iofomo / wing

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
setup.py 3.75 KB
Copy Edit Raw Blame History
chendianbo authored 2024-03-20 23:18 +08:00 . fix shell run fail issue in windows
#!/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' :'rd-share@iofomo.com',
'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()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/iofomo/wing.git
git@gitee.com:iofomo/wing.git
iofomo
wing
wing
master

Search