Skip to content
This repository
Newer
Older
100755 208 lines (193 sloc) 8.075 kb
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
4 # TODO: Get this to be more intelligent about dependencies...
5 # * It should try to automatically install things like html5lib
6 # * We should also add a mechansim for plugins to mark things as dependencies.
7
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
8 from distutils.core import setup
711e02de »
2012-09-21 Added a whole bunch of init scripts to properly daemonize Gate One on…
9 import sys, os, shutil
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
10
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
11 # Globals
12 POSIX = 'posix' in sys.builtin_module_names
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
13 version = '1.1'
14 major, minor = sys.version_info[:2] # Python version
15 if major == 2 and minor <=5:
16 print("Gate One requires Python 2.6+. You are running %s" % sys.version)
17 sys.exit(1)
18 if major == 3:
19 try:
20 import lib2to3 # Just a check--the module is not actually used
21 except ImportError:
22 print("Python 3.X support requires the 2to3 tool.")
23 sys.exit(1)
24
25 # Some paths we can reference
711e02de »
2012-09-21 Added a whole bunch of init scripts to properly daemonize Gate One on…
26 setup_dir = os.path.dirname(os.path.abspath(__file__))
27 build_dir = os.path.join(setup_dir, 'build')
28 if not os.path.exists(build_dir):
29 # Make the build dir a little early so we can use it as a temporary place
30 # to store build files
31 os.mkdir(build_dir)
49fffa91 »
2012-03-02 Fixed a bug where you couldn't run setup.py from outside of the GateO…
32 static_dir = os.path.join(setup_dir, 'gateone', 'static')
33 plugins_dir = os.path.join(setup_dir, 'gateone', 'plugins')
34 templates_dir = os.path.join(setup_dir, 'gateone', 'templates')
35 docs_dir = os.path.join(setup_dir, 'gateone', 'docs')
36 tests_dir = os.path.join(setup_dir, 'gateone', 'tests')
37 i18n_dir = os.path.join(setup_dir, 'gateone', 'i18n')
81ae0e71 »
2012-02-08 DOH: Added the logging and ssh plugin templates to the git repo. NO W…
38 combined_js = os.path.join(static_dir, 'combined_plugins.js')
39 with open(combined_js, 'w') as f:
40 f.write('// This forces the file to be recreated')
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
41
42 if POSIX:
43 prefix = '/opt'
711e02de »
2012-09-21 Added a whole bunch of init scripts to properly daemonize Gate One on…
44 else: # FUTURE
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
45 prefix = os.environ['PROGRAMFILES']
46 print("Gate One will be installed in %s" % prefix)
47
e0e23fae »
2011-11-30 terminal.py: Ampersands are now converted into HTML entities (&amp;) …
48 for arg in sys.argv:
49 if arg.startswith('--prefix') or arg.startswith('--home'):
50 prefix = arg.split('=')[1]
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
51
e0e23fae »
2011-11-30 terminal.py: Ampersands are now converted into HTML entities (&amp;) …
52 def walk_data_files(path, install_path=prefix):
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
53 """
54 Walks *path* and returns a list suitable for use in data_files.
55 *install_path* will be used as the base installation path of the output.
56
57 NOTE: Ignores .git directories.
58 """
59 out = []
60 for (dirpath, dirs, filenames) in os.walk(path):
61 if ".git" in dirs:
62 del dirs[dirs.index(".git")]
63 thesefiles = []
ef40c50e »
2012-03-02 Fixed the setup.py (wasn't installing the subdirectories properly as …
64 shortened_path = dirpath.split(setup_dir)[1][1:]
65 final_path = os.path.join(install_path, shortened_path)
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
66 for fname in filenames:
67 file_path = os.path.join(dirpath, fname)
68 thesefiles.append(file_path)
69 out.append((final_path, thesefiles))
70 return out
71
72 # Take care of our data files
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
73 # Yes, we're treating Python files as data files. Why bother? Because users are
74 # familiar with the setup.py method *and* it can create .rpm files for us (among
75 # other things). Gate One is not a module, after all.
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
76 gateone_files=[ # Start with the basics...
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
77 (os.path.join(prefix, 'gateone'), [
49fffa91 »
2012-03-02 Fixed a bug where you couldn't run setup.py from outside of the GateO…
78 os.path.join(setup_dir, 'gateone', 'auth.py'),
79 os.path.join(setup_dir, 'gateone', 'gateone.py'),
80 os.path.join(setup_dir, 'gateone', 'logviewer.py'),
81 os.path.join(setup_dir, 'gateone', 'sso.py'),
82 os.path.join(setup_dir, 'gateone', 'terminal.py'),
83 os.path.join(setup_dir, 'gateone', 'termio.py'),
84 os.path.join(setup_dir, 'gateone', 'utils.py'),
85 os.path.join(setup_dir, 'gateone', 'authpam.py'),
86 os.path.join(setup_dir, 'gateone', 'remote_syslog.py'),
87 os.path.join(setup_dir, 'README.rst'),
88 os.path.join(setup_dir, 'LICENSE.txt'),
89 os.path.join(setup_dir, 'babel_gateone.cfg')
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
90 ])
91 ]
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
92 static_files = walk_data_files(static_dir)
93 template_files = walk_data_files(templates_dir)
94 docs_files = walk_data_files(docs_dir)
95 plugin_files = walk_data_files(plugins_dir)
96 test_files = walk_data_files(tests_dir)
97 i18n_files = walk_data_files(i18n_dir)
711e02de »
2012-09-21 Added a whole bunch of init scripts to properly daemonize Gate One on…
98
99 # Detect appropriate init script and make sure it is put in the right place
100 init_script = []
101 conf_file = [] # Only used on Gentoo
102 debian_script = os.path.join(setup_dir, 'scripts/init/gateone-debian.sh')
103 redhat_script = os.path.join(setup_dir, 'scripts/init/gateone-redhat.sh')
104 gentoo_script = os.path.join(setup_dir, 'scripts/init/gateone-gentoo.sh')
105 temp_script_path = os.path.join(setup_dir, 'build/gateone')
106 temp_confd_path = os.path.join(setup_dir, 'build/gateone')
107 if os.path.exists('/etc/debian_version'):
108 shutil.copy(debian_script, temp_script_path)
109 elif os.path.exists('/etc/redhat-release'):
110 shutil.copy(debian_script, temp_script_path)
111 elif os.path.exists('/etc/gentoo-release'):
112 shutil.copy(debian_script, temp_script_path)
113 conf_file = [('/etc/conf.d', [
114 os.path.join(setup_dir, 'scripts/conf/gateone')
115 ])]
116
117 if os.path.exists(temp_script_path):
118 init_script = [('/etc/init.d', [
119 temp_script_path
120 ])]
121
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
122 # Put it all together
123 data_files = (
124 gateone_files +
125 static_files +
126 template_files +
127 docs_files +
128 plugin_files +
26606321 »
2011-10-24 Added internationalization (i18n) support. I'm using pybabel to gener…
129 test_files +
711e02de »
2012-09-21 Added a whole bunch of init scripts to properly daemonize Gate One on…
130 i18n_files +
131 init_script +
132 conf_file
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
133 )
134
135 setup(
136 name = 'gateone',
137 license = 'AGPLv3 or Proprietary',
138 version = version,
139 description = 'Web-based Terminal Emulator and SSH Client',
140 long_description = (
0dfa4196 »
2012-03-03 Made a few minor changes to setup.py, setup.cfg, and added a stdeb.cf…
141 'Gate One is a web-based terminal emulator and SSH client that requires'
142 ' no browser plugins and includes many unique and advanced features.'),
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
143 classifiers = [
0dfa4196 »
2012-03-03 Made a few minor changes to setup.py, setup.cfg, and added a stdeb.cf…
144 "Development Status :: 5 - Production/Stable",
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
145 "Operating System :: Unix",
146 "Environment :: Console",
147 "Environment :: Web Environment",
148 "Intended Audience :: End Users/Desktop",
149 "Intended Audience :: Developers",
150 "Intended Audience :: System Administrators",
151 # NOTE: Wish there was a "Tornado" framework option
152 "Programming Language :: Python :: 2.6",
153 "License :: OSI Approved :: GNU Affero General Public License v3",
154 "License :: Other/Proprietary License",
155 "Topic :: Internet :: WWW/HTTP",
156 "Topic :: Terminals"
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
157 ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
158 keywords = (
159 'web administration terminal vt100 xterm emulation html5 console '
160 'web-to-host'),
161 url = "http:/liftoffsoftware.com/Products/GateOne",
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
162 author = 'Dan McDougall',
163 author_email = 'daniel.mcdougall@liftoffsoftware.com',
fe1287b3 »
2012-02-01 TORNADO 2.2 IS OUT. This version is now required to use Gate One as i…
164 requires=["tornado (>=2.2)"],
04f2eabd »
2011-10-12 Commit #1: The Gate One beta is about to go public.
165 provides = ['gateone'],
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
166 data_files = data_files
167 )
168
169 # Python3 support stuff is below
170 def fix_shebang(filepath):
171 """
172 Swaps 'python' for 'python3' in the shebang (if present) in the given
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
173 *filepath*. Returns True if a change was made. False if no changes.
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
174 """
175 contents = []
176 with open(filepath, 'r') as f:
177 contents = f.readlines()
178 if contents and contents[0].startswith('#!'): # Shebang
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
179 if 'python3' in contents[0]:
180 return False # Nothing to do
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
181 with open(filepath, 'w') as f:
182 contents[0] = contents[0].replace('python', 'python3')
183 f.write("".join(contents))
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
184 return True
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
185
186 if major == 3:
187 from subprocess import getstatusoutput
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
188 try:
189 import html5lib
190 except ImportError:
191 # We'll need to use the one bundled with the bookmarks plugin which
192 # means we need to convert it
193 html5lib = None
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
194 command = "2to3 -w -n -x print -x dict -x input %s"
195 for (dirpath, dirs, filenames) in os.walk(os.path.join(prefix, 'gateone')):
196 for f in filenames:
197 if f.endswith('.py'):
198 filepath = os.path.join(dirpath, f)
e148e291 »
2012-09-04 All-around: Fixed a few bugs associated with Python 3 support. Partic…
199 if html5lib: # html5lib is installed
200 # TODO: Add logic to double-check html5lib version
201 if "bookmarks/dependencies/html5lib" in filepath:
202 # Remove it to ensure the installed version gets used
203 os.remove(filepath)
204 continue # Don't bother with the conversion
2aecefae »
2012-04-26 PYTHON 3 SUPPORT HAS BEEN ADDED!
205 print("Converting to python3: %s" % filepath)
206 # Fix the shebang if present
207 fix_shebang(filepath)
208 retcode, output = getstatusoutput(command % filepath)
Something went wrong with that request. Please try again.