Browse Source

Merge pull request #55 from patacrep/cx_freeze

Integration de windows
pull/58/head
Louis 11 years ago
parent
commit
f458c8602a
  1. 1
      Requirements.txt
  2. 11
      install_windows.bat
  3. 20
      patacrep/build.py
  4. 9
      patacrep/content/song.py
  5. 2
      patacrep/data/templates/layout.tex
  6. 2
      patacrep/data/templates/songs.tex
  7. 16
      patacrep/files.py
  8. 5
      patacrep/plastex.py
  9. 8
      patacrep/templates.py
  10. 72
      setup.py
  11. 4
      windows/wget.js

1
Requirements.txt

@ -1,4 +1,5 @@
Jinja2==2.7.3 Jinja2==2.7.3
argparse==1.2.1 argparse==1.2.1
chardet==2.2.1 chardet==2.2.1
unidecode>=0.04.16
https://github.com/tiarno/plastex/archive/master.zip https://github.com/tiarno/plastex/archive/master.zip

11
install_windows.bat

@ -0,0 +1,11 @@
setx path "%path%;C:\Python27;C:\Python27\Scripts;"
setx pathext "%pathext%;.py"
cscript /nologo windows/wget.js https://raw.github.com/pypa/pip/master/contrib/get-pip.py > get-pip.py
C:\Python27\Python.exe get-pip.py
C:\Python27\Scripts\pip install -r Requirements.txt
C:\Python27\Python.exe setup.py install

20
patacrep/build.py

@ -149,6 +149,8 @@ class SongbookBuilder(object):
self._pdflatex_options.append("--shell-escape") self._pdflatex_options.append("--shell-escape")
if not self.interactive: if not self.interactive:
self._pdflatex_options.append("-halt-on-error") self._pdflatex_options.append("-halt-on-error")
for datadir in self.songbook.config["datadir"]:
self._pdflatex_options.append('--include-directory="{}"'.format(datadir))
def build_steps(self, steps=None): def build_steps(self, steps=None):
"""Perform steps on the songbook by calling relevant self.build_*() """Perform steps on the songbook by calling relevant self.build_*()
@ -193,12 +195,18 @@ class SongbookBuilder(object):
"""Build .pdf file from .tex file""" """Build .pdf file from .tex file"""
LOGGER.info("Building '{}.pdf'".format(self.basename)) LOGGER.info("Building '{}.pdf'".format(self.basename))
self._run_once(self._set_latex) self._run_once(self._set_latex)
process = Popen(
["pdflatex"] + self._pdflatex_options + [self.basename], try:
stdin=PIPE, process = Popen(
stdout=PIPE, ["pdflatex"] + self._pdflatex_options + [self.basename],
stderr=PIPE, stdin=PIPE,
env=os.environ) stdout=PIPE,
stderr=PIPE,
env=os.environ)
except Exception as e:
LOGGER.debug(e)
raise errors.LatexCompilationError(self.basename)
if not self.interactive: if not self.interactive:
process.stdin.close() process.stdin.close()
log = '' log = ''

9
patacrep/content/song.py

@ -34,10 +34,11 @@ class SongRenderer(Content, Song):
def render(self, context): def render(self, context):
"""Return the string that will render the song.""" """Return the string that will render the song."""
return ur'\input{{{}}}'.format(files.relpath( return ur'\input{{{}}}'.format(files.path2posix(
self.fullpath, files.relpath(
os.path.dirname(context['filename']) self.fullpath,
)) os.path.dirname(context['filename'])
)))
#pylint: disable=unused-argument #pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config): def parse(keyword, argument, contentlist, config):

2
patacrep/data/templates/layout.tex

@ -28,7 +28,7 @@
\makeatletter \makeatletter
\def\input@path{(* for dir in datadir *) \def\input@path{(* for dir in datadir *)
{((dir))/latex/} % {(( path2posix(dir) ))/latex/} %
(* endfor *) (* endfor *)
} }
\makeatother \makeatother

2
patacrep/data/templates/songs.tex

@ -86,7 +86,7 @@
\usepackage{graphicx} \usepackage{graphicx}
\graphicspath{(* for dir in datadir *) \graphicspath{(* for dir in datadir *)
{((dir))/img/} % {(( path2posix(dir) ))/img/} %
(* endfor *) (* endfor *)
} }

16
patacrep/files.py

@ -7,6 +7,7 @@
from contextlib import contextmanager from contextlib import contextmanager
import fnmatch import fnmatch
import os import os
import posixpath
def recursive_find(root_directory, pattern): def recursive_find(root_directory, pattern):
"""Recursively find files matching a pattern, from a root_directory. """Recursively find files matching a pattern, from a root_directory.
@ -32,6 +33,19 @@ def relpath(path, start=None):
else: else:
return os.path.abspath(path) return os.path.abspath(path)
def path2posix(string):
""""Convert path from local format to posix format."""
if not string or string == "/":
return string
if os.path.splitdrive(string)[1] == "\\":
# Assuming DRIVE:\
return string[0:-1]
(head, tail) = os.path.split(string)
return posixpath.join(
path2posix(head),
tail)
@contextmanager @contextmanager
def chdir(path): def chdir(path):
"""Locally change dir """Locally change dir
@ -40,7 +54,6 @@ def chdir(path):
with chdir("some/directory"): with chdir("some/directory"):
do_stuff() do_stuff()
""" """
olddir = os.getcwd() olddir = os.getcwd()
if path: if path:
@ -49,4 +62,3 @@ def chdir(path):
os.chdir(olddir) os.chdir(olddir)
else: else:
yield yield

5
patacrep/plastex.py

@ -95,7 +95,10 @@ def parsetex(filename):
# /* BEGIN plasTeX patch # /* BEGIN plasTeX patch
if oldlocale[0] and oldlocale[1]: if oldlocale[0] and oldlocale[1]:
locale.setlocale(locale.LC_TIME, "%s.%s" % oldlocale) try:
locale.setlocale(locale.LC_TIME, "%s.%s" % oldlocale)
except locale.Error:
pass # Workaround a bug on windows
# plasTeX patch END */ # plasTeX patch END */
# Extraction des données # Extraction des données

8
patacrep/templates.py

@ -10,8 +10,7 @@ import os
import re import re
import json import json
from patacrep import encoding from patacrep import encoding, errors, files
from patacrep import errors
_LATEX_SUBS = ( _LATEX_SUBS = (
(re.compile(ur'\\'), ur'\\textbackslash'), (re.compile(ur'\\'), ur'\\textbackslash'),
@ -38,7 +37,8 @@ _VARIABLE_REGEXP = re.compile(ur"""
. # Match any single character . # Match any single character
)* # Repeat as often as possible )* # Repeat as often as possible
) # End of capturing group 1 ) # End of capturing group 1
\(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.""", \(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched.
""",
re.VERBOSE|re.DOTALL) re.VERBOSE|re.DOTALL)
@ -96,6 +96,8 @@ class TexRenderer(object):
self.texenv.trim_blocks = True self.texenv.trim_blocks = True
self.texenv.lstrip_blocks = True self.texenv.lstrip_blocks = True
self.texenv.globals["path2posix"] = files.path2posix
try: try:
self.template = self.texenv.get_template(template) self.template = self.texenv.get_template(template)
except TemplateNotFound as exception: except TemplateNotFound as exception:

72
setup.py

@ -4,61 +4,30 @@
$ python setup.py install $ python setup.py install
""" """
from distutils.core import setup
from distutils.command.install import install as _install
from patacrep import __STR_VERSION__ from patacrep import __STR_VERSION__
from distutils.core import setup
import sys import sys
import os import os
import site import site
def link_songbook(): SETUP = {"name": 'patacrep',
if sys.platform.startswith('darwin'): "version": __STR_VERSION__,
source = os.path.join(site.PREFIXES[0], "description": 'Songbook compilation chain',
'bin', "author": 'The Songbook team',
'songbook') "author_email": 'crep@team-on-fire.com',
dest = '/usr/local/bin/songbook' "url": 'https://github.com/patacrep/patacrep',
if os.path.isfile(dest): "packages": ['patacrep', 'patacrep.content'],
print("File {dest} already exist, skipping.".format(dest=dest)) "license": "GPLv2 or any later version",
else: "scripts": ['songbook'],
os.symlink(source, dest) "requires": [
elif sys.platform.startswith('win32'):
script = os.path.join(site.PREFIXES[0],
'Scripts',
'songbook')
dest = script + '.py'
bat_name = script + '.bat'
if os.path.isfile(dest):
os.unlink(dest)
os.rename(script, dest)
content = "python {songbook} %* \n".format(songbook=dest)
with open(bat_name, 'w') as bat_file:
bat_file.write(content)
class install(_install):
def run(self):
_install.run(self)
link_songbook()
setup(cmdclass={'install': install},
name='patacrep',
version=__STR_VERSION__,
description='Songbook compilation chain',
author='The Patacrep team',
author_email='crep@team-on-fire.com',
url='https://github.com/patacrep/patacrep',
packages=['patacrep', 'patacrep.content'],
license="GPLv2 or any later version",
scripts=['songbook'],
requires=[
"argparse", "codecs", "distutils", "fnmatch", "glob", "json", "argparse", "codecs", "distutils", "fnmatch", "glob", "json",
"locale", "logging", "os", "plasTeX", "re", "subprocess", "sys", "locale", "logging", "os", "plasTeX", "re", "subprocess", "sys",
"textwrap", "unidecode", "jinja2" "textwrap", "unidecode", "jinja2", "chardet"
], ],
package_data={'patacrep': ['data/latex/*', "package_data": {'patacrep': [ 'data/latex/*',
'data/templates/*', 'data/templates/*',
'data/examples/*.sb', 'data/examples/*.sb',
'data/examples/*/*.sg', 'data/examples/*/*.sg',
@ -67,7 +36,7 @@ setup(cmdclass={'install': install},
'data/examples/*/*.png', 'data/examples/*/*.png',
'data/examples/*/*.png', 'data/examples/*/*.png',
'data/examples/*/*/header']}, 'data/examples/*/*/header']},
classifiers=[ "classifiers": [
"Environment :: Console", "Environment :: Console",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Natural Language :: English", "Natural Language :: English",
@ -77,5 +46,12 @@ setup(cmdclass={'install': install},
"Programming Language :: Python :: 2.7", "Programming Language :: Python :: 2.7",
"Topic :: Utilities", "Topic :: Utilities",
], ],
platforms=["GNU/Linux", "Windows", "MacOsX"], "platforms": ["GNU/Linux", "Windows", "MacOsX"]
) }
if sys.platform.startswith('win32'):
from shutil import copy
copy("songbook", "songbook.py")
SETUP["scripts"] = ['songbook.py']
setup(**SETUP)

4
windows/wget.js

@ -0,0 +1,4 @@
var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
WinHttpReq.Open("GET", WScript.Arguments(0), /*async=*/false);
WinHttpReq.Send();
WScript.Echo(WinHttpReq.ResponseText);
Loading…
Cancel
Save