mirror of
https://github.com/cheat/cheat.git
synced 2024-11-25 23:41:36 +01:00
adding creation of batch file
This commit is contained in:
parent
371c0af156
commit
538aeee2b2
48
setup.py
48
setup.py
@ -1,5 +1,49 @@
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
import os
|
import os
|
||||||
|
from os.path import join as pjoin, splitext, split as psplit
|
||||||
|
from distutils.command.install_scripts import install_scripts
|
||||||
|
from distutils import log
|
||||||
|
|
||||||
|
BAT_TEMPLATE = \
|
||||||
|
r"""@echo off
|
||||||
|
REM wrapper to use shebang first line of {FNAME}
|
||||||
|
set mypath=%~dp0
|
||||||
|
set pyscript="%mypath%{FNAME}"
|
||||||
|
set /p line1=<%pyscript%
|
||||||
|
if "%line1:~0,2%" == "#!" (goto :goodstart)
|
||||||
|
echo First line of %pyscript% does not start with "#!"
|
||||||
|
exit /b 1
|
||||||
|
:goodstart
|
||||||
|
set py_exe=%line1:~2%
|
||||||
|
call %py_exe% %pyscript% %*
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class my_install_scripts(install_scripts):
|
||||||
|
def run(self):
|
||||||
|
install_scripts.run(self)
|
||||||
|
if not os.name == "nt":
|
||||||
|
return
|
||||||
|
for filepath in self.get_outputs():
|
||||||
|
# If we can find an executable name in the #! top line of the script
|
||||||
|
# file, make .bat wrapper for script.
|
||||||
|
with open(filepath, 'rt') as fobj:
|
||||||
|
first_line = fobj.readline()
|
||||||
|
if not (first_line.startswith('#!') and
|
||||||
|
'python' in first_line.lower()):
|
||||||
|
log.info("No #!python executable found, skipping .bat "
|
||||||
|
"wrapper")
|
||||||
|
continue
|
||||||
|
pth, fname = psplit(filepath)
|
||||||
|
froot, ext = splitext(fname)
|
||||||
|
bat_file = pjoin(pth, froot + '.bat')
|
||||||
|
bat_contents = BAT_TEMPLATE.replace('{FNAME}', fname)
|
||||||
|
log.info("Making %s wrapper for %s" % (bat_file, filepath))
|
||||||
|
if self.dry_run:
|
||||||
|
continue
|
||||||
|
with open(bat_file, 'wt') as fobj:
|
||||||
|
fobj.write(bat_contents)
|
||||||
|
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
('/usr/share/zsh/site-functions', ['cheat/autocompletion/_cheat.zsh']),
|
('/usr/share/zsh/site-functions', ['cheat/autocompletion/_cheat.zsh']),
|
||||||
@ -34,5 +78,7 @@ setup(
|
|||||||
install_requires = [
|
install_requires = [
|
||||||
'docopt >= 0.6.1',
|
'docopt >= 0.6.1',
|
||||||
'pygments >= 1.6.0',
|
'pygments >= 1.6.0',
|
||||||
]
|
],
|
||||||
|
cmdclass = {'install_scripts': my_install_scripts}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user