Lines 52-58
_ = Translation('univention-directory-reports').translate
|
Link Here
|
---|
|
52 |
|
52 |
|
53 |
|
53 |
|
54 |
class Document(object): |
54 |
class Document(object): |
55 |
(TYPE_LATEX, TYPE_CSV, TYPE_RML, TYPE_UNKNOWN) = range(4) |
55 |
(TYPE_LATEX, TYPE_CSV, TYPE_RML, TYPE_SCRIPT, TYPE_UNKNOWN) = range(5) |
56 |
|
56 |
|
57 |
@classmethod |
57 |
@classmethod |
58 |
def get_type(cls, template): |
58 |
def get_type(cls, template): |
Lines 62-67
class Document(object):
|
Link Here
|
---|
|
62 |
return cls.TYPE_CSV |
62 |
return cls.TYPE_CSV |
63 |
elif template.endswith('.rml'): |
63 |
elif template.endswith('.rml'): |
64 |
return cls.TYPE_RML |
64 |
return cls.TYPE_RML |
|
|
65 |
elif template.endswith('.py') or template.endswith('.sh'): |
66 |
return cls.TYPE_SCRIPT |
65 |
return cls.TYPE_UNKNOWN |
67 |
return cls.TYPE_UNKNOWN |
66 |
|
68 |
|
67 |
def __init__(self, template, header=None, footer=None): |
69 |
def __init__(self, template, header=None, footer=None): |
Lines 88-94
class Document(object):
|
Link Here
|
---|
|
88 |
elif self._type == Document.TYPE_CSV: |
90 |
elif self._type == Document.TYPE_CSV: |
89 |
suffix = '.csv' |
91 |
suffix = '.csv' |
90 |
else: |
92 |
else: |
91 |
suffix = self._template.rsplit('.', 1)[1] |
93 |
suffix = '.' + self._template.rsplit('.', 1)[1] |
92 |
fd, filename = tempfile.mkstemp(suffix, 'univention-directory-reports-') |
94 |
fd, filename = tempfile.mkstemp(suffix, 'univention-directory-reports-') |
93 |
os.chmod(filename, 0o644) |
95 |
os.chmod(filename, 0o644) |
94 |
os.close(fd) |
96 |
os.close(fd) |
Lines 138-144
class Document(object):
|
Link Here
|
---|
|
138 |
|
140 |
|
139 |
return tmpfile |
141 |
return tmpfile |
140 |
|
142 |
|
141 |
def create_pdf(self, latex_file): |
143 |
def create_pdf(self, latex_file, objects): |
142 |
"""Run pdflatex on latex_file and return path to generated file or None on errors.""" |
144 |
"""Run pdflatex on latex_file and return path to generated file or None on errors.""" |
143 |
cmd = ['/usr/bin/pdflatex', '-interaction=nonstopmode', '-halt-on-error', '-output-directory=%s' % os.path.dirname(latex_file), latex_file] |
145 |
cmd = ['/usr/bin/pdflatex', '-interaction=nonstopmode', '-halt-on-error', '-output-directory=%s' % os.path.dirname(latex_file), latex_file] |
144 |
devnull = open(os.path.devnull, 'w') |
146 |
devnull = open(os.path.devnull, 'w') |
Lines 157-163
class Document(object):
|
Link Here
|
---|
|
157 |
except EnvironmentError: |
159 |
except EnvironmentError: |
158 |
pass |
160 |
pass |
159 |
|
161 |
|
160 |
def create_rml_pdf(self, rml_file): |
162 |
def create_rml_pdf(self, rml_file, objects): |
161 |
output = '%s.pdf' % (os.path.splitext(rml_file)[0],) |
163 |
output = '%s.pdf' % (os.path.splitext(rml_file)[0],) |
162 |
with open(rml_file, 'rb') as fd: |
164 |
with open(rml_file, 'rb') as fd: |
163 |
outputfile = trml2pdf.parseString(fd.read(), output) |
165 |
outputfile = trml2pdf.parseString(fd.read(), output) |
Lines 166-168
class Document(object):
|
Link Here
|
---|
|
166 |
except EnvironmentError: |
168 |
except EnvironmentError: |
167 |
pass |
169 |
pass |
168 |
return outputfile |
170 |
return outputfile |
|
|
171 |
|
172 |
def create_from_script(self, script_file, objects): |
173 |
output = '%s.csv' % (os.path.splitext(script_file)[0],) |
174 |
with open(output, 'w') as fd: |
175 |
fd.write(subprocess.check_output([sys.executable, script_file] + objects)) |
176 |
return output |