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
argparse==1.2.1
chardet==2.2.1
unidecode>=0.04.16
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")
if not self.interactive:
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):
"""Perform steps on the songbook by calling relevant self.build_*()
@ -193,12 +195,18 @@ class SongbookBuilder(object):
"""Build .pdf file from .tex file"""
LOGGER.info("Building '{}.pdf'".format(self.basename))
self._run_once(self._set_latex)
process = Popen(
["pdflatex"] + self._pdflatex_options + [self.basename],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
env=os.environ)
try:
process = Popen(
["pdflatex"] + self._pdflatex_options + [self.basename],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
env=os.environ)
except Exception as e:
LOGGER.debug(e)
raise errors.LatexCompilationError(self.basename)
if not self.interactive:
process.stdin.close()
log = ''

9
patacrep/content/song.py

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

2
patacrep/data/templates/layout.tex

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

2
patacrep/data/templates/songs.tex

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

16
patacrep/files.py

@ -7,6 +7,7 @@
from contextlib import contextmanager
import fnmatch
import os
import posixpath
def recursive_find(root_directory, pattern):
"""Recursively find files matching a pattern, from a root_directory.
@ -32,6 +33,19 @@ def relpath(path, start=None):
else:
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
def chdir(path):
"""Locally change dir
@ -40,7 +54,6 @@ def chdir(path):
with chdir("some/directory"):
do_stuff()
"""
olddir = os.getcwd()
if path:
@ -49,4 +62,3 @@ def chdir(path):
os.chdir(olddir)
else:
yield

5
patacrep/plastex.py

@ -95,7 +95,10 @@ def parsetex(filename):
# /* BEGIN plasTeX patch
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 */
# Extraction des données

8
patacrep/templates.py

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

72
setup.py

@ -4,61 +4,30 @@
$ python setup.py install
"""
from distutils.core import setup
from distutils.command.install import install as _install
from patacrep import __STR_VERSION__
from distutils.core import setup
import sys
import os
import site
def link_songbook():
if sys.platform.startswith('darwin'):
source = os.path.join(site.PREFIXES[0],
'bin',
'songbook')
dest = '/usr/local/bin/songbook'
if os.path.isfile(dest):
print("File {dest} already exist, skipping.".format(dest=dest))
else:
os.symlink(source, dest)
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=[
SETUP = {"name": 'patacrep',
"version": __STR_VERSION__,
"description": 'Songbook compilation chain',
"author": 'The Songbook 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",
"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/examples/*.sb',
'data/examples/*/*.sg',
@ -67,7 +36,7 @@ setup(cmdclass={'install': install},
'data/examples/*/*.png',
'data/examples/*/*.png',
'data/examples/*/*/header']},
classifiers=[
"classifiers": [
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Natural Language :: English",
@ -77,5 +46,12 @@ setup(cmdclass={'install': install},
"Programming Language :: Python :: 2.7",
"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