forked from liftoff/GateOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·158 lines (147 loc) · 5.77 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
import sys, os
# Globals
POSIX = 'posix' in sys.builtin_module_names
version = '1.1'
setup_dir = os.path.dirname(os.path.abspath(__file__))
major, minor = sys.version_info[:2] # Python version
if major == 2 and minor <=5:
print("Gate One requires Python 2.6+. You are running %s" % sys.version)
sys.exit(1)
if major == 3:
try:
import lib2to3 # Just a check--the module is not actually used
except ImportError:
print("Python 3.X support requires the 2to3 tool.")
sys.exit(1)
# Some paths we can reference
static_dir = os.path.join(setup_dir, 'gateone', 'static')
plugins_dir = os.path.join(setup_dir, 'gateone', 'plugins')
templates_dir = os.path.join(setup_dir, 'gateone', 'templates')
docs_dir = os.path.join(setup_dir, 'gateone', 'docs')
tests_dir = os.path.join(setup_dir, 'gateone', 'tests')
i18n_dir = os.path.join(setup_dir, 'gateone', 'i18n')
combined_js = os.path.join(static_dir, 'combined_plugins.js')
with open(combined_js, 'w') as f:
f.write('// This forces the file to be recreated')
if POSIX:
prefix = '/opt'
else:
prefix = os.environ['PROGRAMFILES']
print("Gate One will be installed in %s" % prefix)
for arg in sys.argv:
if arg.startswith('--prefix') or arg.startswith('--home'):
prefix = arg.split('=')[1]
def walk_data_files(path, install_path=prefix):
"""
Walks *path* and returns a list suitable for use in data_files.
*install_path* will be used as the base installation path of the output.
NOTE: Ignores .git directories.
"""
out = []
for (dirpath, dirs, filenames) in os.walk(path):
if ".git" in dirs:
del dirs[dirs.index(".git")]
thesefiles = []
shortened_path = dirpath.split(setup_dir)[1][1:]
final_path = os.path.join(install_path, shortened_path)
for fname in filenames:
file_path = os.path.join(dirpath, fname)
thesefiles.append(file_path)
out.append((final_path, thesefiles))
return out
# Take care of our data files
# Yes, we're treating Python files as data files. Why bother? Because users are
# familiar with the setup.py method *and* it can create .rpm files for us (among
# other things). Gate One is not a module, after all.
gateone_files=[ # Start with the basics...
(os.path.join(prefix, 'gateone'), [
os.path.join(setup_dir, 'gateone', 'auth.py'),
os.path.join(setup_dir, 'gateone', 'gateone.py'),
os.path.join(setup_dir, 'gateone', 'logviewer.py'),
os.path.join(setup_dir, 'gateone', 'sso.py'),
os.path.join(setup_dir, 'gateone', 'terminal.py'),
os.path.join(setup_dir, 'gateone', 'termio.py'),
os.path.join(setup_dir, 'gateone', 'utils.py'),
os.path.join(setup_dir, 'gateone', 'authpam.py'),
os.path.join(setup_dir, 'gateone', 'remote_syslog.py'),
os.path.join(setup_dir, 'README.rst'),
os.path.join(setup_dir, 'LICENSE.txt'),
os.path.join(setup_dir, 'babel_gateone.cfg')
])
]
static_files = walk_data_files(static_dir)
template_files = walk_data_files(templates_dir)
docs_files = walk_data_files(docs_dir)
plugin_files = walk_data_files(plugins_dir)
test_files = walk_data_files(tests_dir)
i18n_files = walk_data_files(i18n_dir)
# Put it all together
data_files = (
gateone_files +
static_files +
template_files +
docs_files +
plugin_files +
test_files +
i18n_files
)
setup(
name = 'gateone',
license = 'AGPLv3 or Proprietary',
version = version,
description = 'Web-based Terminal Emulator and SSH Client',
long_description = (
'Gate One is a web-based terminal emulator and SSH client that requires'
' no browser plugins and includes many unique and advanced features.'),
classifiers = [
"Development Status :: 5 - Production/Stable",
"Operating System :: Unix",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
# NOTE: Wish there was a "Tornado" framework option
"Programming Language :: Python :: 2.6",
"License :: OSI Approved :: GNU Affero General Public License v3",
"License :: Other/Proprietary License",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Terminals"
], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords = (
'web administration terminal vt100 xterm emulation html5 console '
'web-to-host'),
url = "http:/liftoffsoftware.com/Products/GateOne",
author = 'Dan McDougall',
author_email = '[email protected]',
requires=["tornado (>=2.2)"],
provides = ['gateone'],
data_files = data_files
)
# Python3 support stuff is below
def fix_shebang(filepath):
"""
Swaps 'python' for 'python3' in the shebang (if present) in the given
*filepath*.
"""
contents = []
with open(filepath, 'r') as f:
contents = f.readlines()
if contents and contents[0].startswith('#!'): # Shebang
with open(filepath, 'w') as f:
contents[0] = contents[0].replace('python', 'python3')
f.write("".join(contents))
if major == 3:
from subprocess import getstatusoutput
command = "2to3 -w -n -x print -x dict -x input %s"
for (dirpath, dirs, filenames) in os.walk(os.path.join(prefix, 'gateone')):
for f in filenames:
if f.endswith('.py'):
filepath = os.path.join(dirpath, f)
print("Converting to python3: %s" % filepath)
# Fix the shebang if present
fix_shebang(filepath)
retcode, output = getstatusoutput(command % filepath)