-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoffline.py
79 lines (64 loc) · 2.34 KB
/
offline.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
#!/usr/bin/env python3
"""
Offline installation of NITA CLI
"""
# Always prefer setuptools over distutils
#from setuptools import setup, find_packages
import platform
import subprocess
import os
import re
def get_env_prefix():
"""
Automatically identify os_type information which use for
install path of bash_completion.d
"""
TARGET_BIN_PATH = '/usr/local/bin/'
os_type = platform.system()
cygwin = r'CYGWIN|cygwin'
if os_type == "Linux":
TARGET_COMPLETION_PATH = "/etc/bash_completion.d/"
# Darwin is indicate Mac OS
elif os_type == "Darwin":
proc = subprocess.Popen(
'brew --prefix', shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
brew_prefix = "{0}/etc/bash_completion.d/".format(
stdout.rstrip().decode("utf-8"))
TARGET_COMPLETION_PATH = brew_prefix
# Return true if CYGWIN or cygwin there in os type string
elif re.search(cygwin, os_type):
TARGET_COMPLETION_PATH = '/etc/bash_completion.d/'
TARGET_BIN_PATH = '/usr/bin/'
if not os.path.exists(TARGET_COMPLETION_PATH):
os.makedirs(TARGET_COMPLETION_PATH)
else:
raise ValueError(
'Unknown OS type found. This Operating System is not supported.')
return TARGET_COMPLETION_PATH, TARGET_BIN_PATH
def run_autocomplete():
"""
Run script that Generate file nita autocompletion.
"""
cmd = 'python3 autocomplete'
proc = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
def cp_nita(TARGET_COMPLETION_PATH):
"""
Copy nita to /usr/local/bin/ and to autocompletion path.
"""
subprocess.call(['cp', 'nita', '/usr/local/bin/nita'])
subprocess.call(['cp', 'bash_completion.d/nita', TARGET_COMPLETION_PATH + 'nita'])
TARGET_COMPLETION_PATH, TARGET_BIN_PATH = get_env_prefix()
run_autocomplete()
# Include data files if those exist
# for that we iterate the folder and append the files
data_files_list = [(TARGET_BIN_PATH, ['nita'])]
for file in os.listdir('bash_completion.d/'):
f1 = 'bash_completion.d/' + file
if os.path.isfile(f1): # skip directories
data_files_list.append((TARGET_COMPLETION_PATH, [f1]))
# Copy nita to /usr/local/bin/
cp_nita(TARGET_COMPLETION_PATH)