setup.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 # -*- coding: utf-8 -*-
00004 
00005 '''rtshell
00006 
00007 Copyright (C) 2009-2014
00008     Geoffrey Biggs
00009     RT-Synthesis Research Group
00010     Intelligent Systems Research Institute,
00011     National Institute of Advanced Industrial Science and Technology (AIST),
00012     Japan
00013     All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016 
00017 File: setup.py
00018 
00019 rtshell install script.
00020 
00021 '''
00022 
00023 # $Source$
00024 
00025 
00026 from distutils.command.install_scripts import install_scripts
00027 from distutils.command.install_data import install_data
00028 from distutils.core import setup
00029 import os
00030 import os.path
00031 import subprocess
00032 import sys
00033 
00034 
00035 # Hacky method of installing the documentation. Need a nice hook for this.
00036 def get_files(dir, ext=None):
00037     files = [os.path.join(dir, f) for f in os.listdir(dir) \
00038             if os.path.isfile(os.path.join(dir, f))]
00039     if ext:
00040         return [f for f in files if os.path.splitext(f)[1] == ext]
00041     else:
00042         return files
00043 
00044 if sys.platform != 'win32':
00045     cwd = os.path.join(os.getcwd(), 'doc')
00046     #s = raw_input('Generate documentation? ')
00047     s = 'y'
00048     if s.lower() == 'y' or s.lower() == 'YES':
00049         print 'Generating documentation'
00050         p = subprocess.Popen(['./make_docs', 'man', 'html', 'pdf', '-v'],
00051                 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
00052         stdout, stderr = p.communicate()
00053         if p.returncode != 0:
00054             print 'Failed to generate documentation. Check docutils are installed.'
00055             print stderr
00056 try:
00057     man_files_en = get_files(os.path.join(os.getcwd(), 'doc/man/man1'))
00058     html_files_en = get_files(os.path.join(os.getcwd(), 'doc/html'))
00059     pdf_files_en = get_files(os.path.join(os.getcwd(), 'doc/pdf'), ext='.pdf')
00060     man_files_ja = get_files(os.path.join(os.getcwd(), 'doc/man/ja/man1'))
00061     html_files_ja = get_files(os.path.join(os.getcwd(), 'doc/html/ja'))
00062     pdf_files_ja = get_files(os.path.join(os.getcwd(), 'doc/pdf/ja'), ext='.pdf')
00063 except OSError:
00064     man_files_en = []
00065     html_files_en = []
00066     pdf_files_en = []
00067     man_files_ja = []
00068     html_files_ja = []
00069     pdf_files_ja = []
00070 
00071 
00072 base_scripts = ['rtact',
00073                 'rtcat',
00074                 'rtcheck',
00075                 'rtcomp',
00076                 'rtcon',
00077                 'rtconf',
00078                 'rtcryo',
00079                 'rtdeact',
00080                 'rtdel',
00081                 'rtdis',
00082                 'rtexit',
00083                 'rtfind',
00084                 'rtinject',
00085                 'rtlog',
00086                 'rtls',
00087                 'rtdoc',
00088                 'rtmgr',
00089                 'rtprint',
00090                 'rtpwd',
00091                 'rtreset',
00092                 'rtresurrect',
00093                 'rtstart',
00094                 'rtstodot',
00095                 'rtstop',
00096                 'rtteardown',
00097                 'rtvlog']
00098 if sys.platform == 'win32':
00099     batch_files = ['rtact.bat',
00100                    'rtcat.bat',
00101                    'rtcheck.bat',
00102                    'rtcomp.bat',
00103                    'rtcon.bat',
00104                    'rtconf.bat',
00105                    'rtcryo.bat',
00106                    'rtcwd.bat',
00107                    'rtdeact.bat',
00108                    'rtdel.bat',
00109                    'rtdis.bat',
00110                    'rtdoc.bat',
00111                    'rtexit.bat',
00112                    'rtfind.bat',
00113                    'rtinject.bat',
00114                    'rtlog.bat',
00115                    'rtls.bat',
00116                    'rtmgr.bat',
00117                    'rtprint.bat',
00118                    'rtpwd.bat',
00119                    'rtreset.bat',
00120                    'rtresurrect.bat',
00121                    'rtstart.bat',
00122                    'rtstop.bat',
00123                    'rtteardown.bat',
00124                    'rtvlog.bat']
00125     scripts = base_scripts + batch_files
00126     data_files = [('Doc/rtshell', html_files_en + pdf_files_en),
00127             ('Doc/rtshell/ja', html_files_ja + pdf_files_ja)]
00128 else:
00129     scripts = base_scripts
00130     data_files = [('share/rtshell', ['bash_completion', 'shell_support.in']),
00131             ('share/man/man1', man_files_en),
00132             ('share/man/ja/man1', man_files_ja),
00133             ('share/doc/rtshell', html_files_en + pdf_files_en),
00134             ('share/doc/rtshell/ja', html_files_ja + pdf_files_ja)]
00135 
00136 
00137 class InstallRename(install_scripts):
00138     def run(self):
00139         install_scripts.run(self)
00140         if sys.platform == 'win32':
00141             # Rename the installed scripts to add .py on the end for Windows
00142             print 'Renaming scripts'
00143             for s in base_scripts:
00144                 dest = os.path.join(self.install_dir, s + '.py')
00145                 if os.path.exists(dest):
00146                     os.remove(dest)
00147                 self.move_file(os.path.join(self.install_dir, s), dest)
00148             # Make links for the docs
00149             #print 'Creating Start Menu links'
00150             #rtshell_dir = os.path.join(self._get_start_menu(), 'rtshell')
00151             #if not os.path.exists(rtshell_dir):
00152                 #os.mkdir(rtshell_dir)
00153             #docs_en_path = os.path.join(rtshell_dir,
00154                     #'Documentation (English).url')
00155             #docs_ja_path = os.path.join(rtshell_dir,
00156                     #'Documentation (Japanese).lnk')
00157 
00158     def _get_start_menu(self):
00159         if sys.platform != 'win32':
00160             return ''
00161         import ctypes
00162         import ctypes.wintypes
00163         SHGetFolderPath = ctypes.windll.shell32.SHGetFolderPathW
00164         SHGetFolderPath.argtypes = [ctypes.wintypes.HWND, ctypes.c_int,
00165                 ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD,
00166                 ctypes.wintypes.LPCWSTR]
00167         path = ctypes.wintypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
00168         SHGetFolderPath(0, 2, 0, 0, path)
00169         return path.value
00170 
00171 
00172 class InstallConfigure(install_data):
00173     def run(self):
00174         install_data.run(self)
00175         if sys.platform != 'win32':
00176             cmd = 'echo $SHELL | grep -q bash && source {dir}/bash_completion\n'
00177             dest = os.path.join(self.install_dir, 'share/rtshell', 'shell_support')
00178             if os.path.isfile(dest):
00179                 os.remove(dest)
00180             self.move_file(os.path.join(self.install_dir, 'share/rtshell',
00181                     'shell_support.in'), dest)
00182             with open(dest, 'a') as f:
00183                 if self.root:
00184                     rtshell_path = os.path.join('/',os.path.relpath(self.install_dir,self.root))
00185                 else:
00186                     rtshell_path = self.install_dir
00187                 f.writelines((cmd.format(dir=os.path.join(rtshell_path,
00188                     'share/rtshell')), '\n'))
00189             self.config_bash_compl()
00190 
00191     def config_bash_compl(self):
00192         COMPOPT_NOSPACE = 'compopt -o nospace'
00193         COMPOPT_FILENAME = 'compopt -o filenames'
00194         COMPLETE_NOSPACE = '-o nospace'
00195         compl_script = '{0}/bash_completion'.format(
00196                 os.path.join(self.install_dir, 'share/rtshell'))
00197         if sys.platform == 'darwin':
00198             replace = ['-e', 's/@COMPOPT_NOSPACE@/:/g', '-e',
00199                     's/@COMPOPT_FILENAME@/:/g', '-e',
00200                     's/@COMPLETE_NOSPACE@/{0}/g'.format(COMPLETE_NOSPACE)]
00201         else:
00202             replace = ['-e', "'s/@COMPOPT_NOSPACE@/{0}/g'".format(
00203                 COMPOPT_NOSPACE), '-e', "'s/@COMPOPT_FILENAME@/{0}/g'".format(
00204                 COMPOPT_FILENAME), '-e', "'s/@COMPLETE_NOSPACE@//g'"]
00205         p = subprocess.Popen(['sed'] + replace + ['-i', '', compl_script],
00206                 stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd)
00207         stdout, stderr = p.communicate()
00208         if p.returncode != 0:
00209             print 'Failed to filter bash_completion.'
00210             print stderr
00211 
00212 
00213 setup(name='rtshell',
00214       version='4.0.0',
00215       description='Shell commands for managing RT Components and RT Systems.',
00216       author='Geoffrey Biggs and contributors',
00217       author_email='git@killbots.net',
00218       url='http://github.com/gbiggs/rtshell',
00219       license='EPL',
00220       long_description='Shell commands for managing RT-Middleware.',
00221       classifiers=[
00222           'Development Status :: 5 - Production/Stable',
00223           'Environment :: Console',
00224           'Intended Audience :: Developers',
00225           'License :: OSI Approved :: EPL License',
00226           'Natural Language :: English',
00227           'Operating System :: OS Independent',
00228           'Programming Language :: Python :: 2.6',
00229           'Programming Language :: Python :: 2.7',
00230           'Topic :: Software Development',
00231           'Topic :: Utilities'
00232           ],
00233       packages=['rtshell'],
00234       scripts=scripts,
00235       data_files=data_files,
00236       cmdclass={'install_scripts':InstallRename,
00237           'install_data':InstallConfigure}
00238       )
00239 
00240 
00241 # vim: tw=79
00242 


rtshell
Author(s): Geoffrey Biggs
autogenerated on Fri Aug 28 2015 12:55:12