Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
schildergenerator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schilder
schildergenerator
Commits
22b9a6c5
Verified
Commit
22b9a6c5
authored
5 years ago
by
Robin Sonnabend
Browse files
Options
Downloads
Patches
Plain Diff
Run 2to3
parent
f03c6dc2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
schilder.py
+22
-22
22 additions, 22 deletions
schilder.py
with
22 additions
and
22 deletions
schilder.py
+
22
−
22
View file @
22b9a6c5
#!/usr/bin/env python
2
#!/usr/bin/env python
3
# -*- encoding: utf8 -*-
from
flask
import
Flask
,
flash
,
session
,
redirect
,
url_for
,
escape
,
request
,
Response
,
Markup
...
...
@@ -25,7 +25,7 @@ app = Flask(__name__)
app
.
config
.
update
(
UPLOAD_FOLDER
=
config
.
uploaddir
,
PROPAGATE_EXCEPTIONS
=
True
,
MAX_CONTENT_LENGTH
=
8388608
L
MAX_CONTENT_LENGTH
=
8388608
)
app
.
secret_key
=
config
.
app_secret
genshi
=
Genshi
(
app
)
...
...
@@ -82,7 +82,7 @@ def save_data(formdata, outfilename):
json
.
dump
(
formdata
,
outfile
)
def
run_pdflatex
(
context
,
outputfilename
,
overwrite
=
True
):
if
not
context
.
has_key
(
'
textemplate
'
)
:
if
'
textemplate
'
not
in
context
:
context
[
'
textemplate
'
]
=
"
text-image-quer.tex
"
genshitex
=
TemplateLoader
([
config
.
textemplatedir
])
template
=
genshitex
.
load
(
...
...
@@ -93,7 +93,7 @@ def run_pdflatex(context, outputfilename, overwrite=True):
context
[
'
text
'
]
=
publish_parts
(
context
[
'
text
'
],
writer_name
=
'
latex
'
)[
'
body
'
]
#context['headline'] = publish_parts(context['headline'], writer_name='latex')['body']
tmpdir
=
tempfile
.
mkdtemp
(
dir
=
config
.
tmpdir
)
if
context
.
has_key
(
'
img
'
)
and
context
[
'
img
'
]
and
context
[
'
img
'
]
!=
'
__none
'
:
if
'
img
'
in
context
and
context
[
'
img
'
]
and
context
[
'
img
'
]
!=
'
__none
'
:
try
:
shutil
.
copy
(
os
.
path
.
join
(
config
.
imagedir
,
context
[
'
img
'
]),
os
.
path
.
join
(
tmpdir
,
context
[
'
img
'
]))
...
...
@@ -117,7 +117,7 @@ def run_pdflatex(context, outputfilename, overwrite=True):
try
:
flash
(
Markup
(
"
<p>PDFLaTeX Output:</p><pre>%s</pre>
"
%
e
.
output
),
'
log
'
)
except
:
print
(
e
.
output
)
print
(
(
e
.
output
)
)
raise
SyntaxWarning
(
"
PDFLaTeX bailed out
"
)
finally
:
os
.
chdir
(
cwd
)
...
...
@@ -163,7 +163,7 @@ def index(**kwargs):
data
=
defaultdict
(
str
)
data
.
update
(
**
kwargs
)
filelist
=
glob
.
glob
(
config
.
datadir
+
'
/*.schild
'
)
data
[
'
files
'
]
=
[
unicode
(
os
.
path
.
basename
(
f
))
for
f
in
sorted
(
filelist
)]
data
[
'
files
'
]
=
[
str
(
os
.
path
.
basename
(
f
))
for
f
in
sorted
(
filelist
)]
return
render_response
(
'
index.html
'
,
data
)
...
...
@@ -174,7 +174,7 @@ def edit(**kwargs):
imagelist
=
sorted
(
glob
.
glob
(
config
.
imagedir
+
'
/*.png
'
))
data
[
'
images
'
]
=
[
os
.
path
.
basename
(
f
)
for
f
in
imagelist
]
templatelist
=
glob
.
glob
(
config
.
textemplatedir
+
'
/*.tex
'
)
data
[
'
templates
'
]
=
[
unicode
(
os
.
path
.
basename
(
f
))
data
[
'
templates
'
]
=
[
str
(
os
.
path
.
basename
(
f
))
for
f
in
sorted
(
templatelist
)]
data
[
'
imageextensions
'
]
=
config
.
allowed_extensions
return
render_response
(
'
edit.html
'
,
data
)
...
...
@@ -190,7 +190,7 @@ def create():
if
request
.
method
==
'
POST
'
:
formdata
=
defaultdict
(
str
,
request
.
form
.
to_dict
(
flat
=
True
))
for
a
in
(
'
headline
'
,
'
text
'
):
formdata
[
a
]
=
unicode
(
formdata
[
a
])
formdata
[
a
]
=
str
(
formdata
[
a
])
try
:
imgpath
=
save_and_convert_image_upload
(
'
imgupload
'
)
if
imgpath
is
not
None
:
...
...
@@ -205,18 +205,18 @@ def create():
save_data
(
formdata
,
outfilename
)
run_pdflatex
(
formdata
,
os
.
path
.
join
(
config
.
pdfdir
,
outpdfname
))
try
:
flash
(
Markup
(
u
"""
PDF created and data saved. You might create another one. Here
'
s a preview. Click to print.<br/>
flash
(
Markup
(
"""
PDF created and data saved. You might create another one. Here
'
s a preview. Click to print.<br/>
<a href=
"
%s
"
><img src=
"
%s
"
/></a>
"""
%
(
url_for
(
'
schild
'
,
filename
=
outfilename
),
url_for
(
'
pdfthumbnail
'
,
pdfname
=
outpdfname
,
maxgeometry
=
200
))
))
except
:
print
(
"
%s created
"
%
outpdfname
)
print
(
(
"
%s created
"
%
outpdfname
)
)
except
Exception
as
e
:
try
:
flash
(
u
"
Could not create pdf or save data: %s
"
%
str
(
e
),
'
error
'
)
flash
(
"
Could not create pdf or save data: %s
"
%
str
(
e
),
'
error
'
)
except
:
print
(
"
Could not create pdf or save data: %s
"
%
str
(
e
))
print
(
(
"
Could not create pdf or save data: %s
"
%
str
(
e
))
)
data
=
{
'
form
'
:
formdata
}
imagelist
=
glob
.
glob
(
config
.
imagedir
+
'
/*.png
'
)
...
...
@@ -236,7 +236,7 @@ def create():
@app.route
(
'
/schild/<filename>
'
)
def
schild
(
filename
):
return
render_response
(
'
schild.html
'
,
{
'
filename
'
:
filename
,
'
printer
'
:
[
unicode
(
f
)
for
f
in
sorted
(
config
.
printers
.
keys
())]})
return
render_response
(
'
schild.html
'
,
{
'
filename
'
:
filename
,
'
printer
'
:
[
str
(
f
)
for
f
in
sorted
(
config
.
printers
.
keys
())]})
@app.route
(
'
/printout
'
,
methods
=
[
'
POST
'
])
...
...
@@ -249,11 +249,11 @@ def printout():
try
:
lprout
=
check_output
([
'
lpr
'
,
'
-H
'
,
str
(
config
.
printserver
),
'
-P
'
,
str
(
printer
),
'
-#
'
,
str
(
copies
)]
+
config
.
lproptions
+
[
filename
],
stderr
=
STDOUT
)
flash
(
u
'
Schild wurde zum Drucker geschickt!
'
)
flash
(
'
Schild wurde zum Drucker geschickt!
'
)
except
CalledProcessError
as
e
:
flash
(
Markup
(
"
<p>Could not print:</p><pre>%s</pre>
"
%
e
.
output
),
'
error
'
)
else
:
flash
(
u
'
Ungültige Anzahl Kopien!
'
)
flash
(
'
Ungültige Anzahl Kopien!
'
)
return
redirect
(
url_for
(
'
index
'
))
def
delete_file
(
filename
):
...
...
@@ -261,10 +261,10 @@ def delete_file(filename):
os
.
unlink
(
os
.
path
.
join
(
config
.
datadir
,
filename
))
for
f
in
glob
.
glob
(
os
.
path
.
join
(
config
.
pdfdir
,
filename
+
'
.pdf*
'
)):
os
.
unlink
(
f
)
flash
(
u
"
Schild %s wurde gelöscht
"
%
filename
)
flash
(
"
Schild %s wurde gelöscht
"
%
filename
)
return
redirect
(
url_for
(
'
index
'
))
except
:
flash
(
u
"
Schild %s konnte nicht gelöscht werden.
"
%
filename
,
'
error
'
)
flash
(
"
Schild %s konnte nicht gelöscht werden.
"
%
filename
,
'
error
'
)
return
redirect
(
url_for
(
'
schild
'
,
filename
=
filename
))
...
...
@@ -312,8 +312,8 @@ def tplthumbnail(tplname, maxgeometry):
run_pdflatex
(
{
'
textemplate
'
:
secure_filename
(
tplname
),
'
img
'
:
'
pictograms-nps-misc-camera.png
'
,
'
headline
'
:
u
'
Überschrift
'
,
'
text
'
:
u
'
Dies ist der Text, der in der UI als Text bezeichnet ist.
'
,
'
headline
'
:
'
Überschrift
'
,
'
text
'
:
'
Dies ist der Text, der in der UI als Text bezeichnet ist.
'
,
'
markup
'
:
'
latex
'
,
},
pdfpath
,
overwrite
=
False
)
...
...
@@ -338,13 +338,13 @@ def recreate_cache():
glob
.
glob
(
os
.
path
.
join
(
config
.
imagedir
,
'
*.png.*
'
))):
try
:
os
.
unlink
(
filename
)
print
(
"
Deleted %s
"
%
filename
)
print
(
(
"
Deleted %s
"
%
filename
)
)
except
Exception
as
e
:
print
(
"
Could not delete %s: %s
"
%
(
filename
,
str
(
e
)))
print
(
(
"
Could not delete %s: %s
"
%
(
filename
,
str
(
e
)))
)
for
filename
in
glob
.
glob
(
os
.
path
.
join
(
config
.
datadir
,
'
*.schild
'
)):
data
=
load_data
(
filename
)
pdfname
=
os
.
path
.
join
(
config
.
pdfdir
,
data
[
'
pdfname
'
])
print
(
"
Recreating %s
"
%
pdfname
)
print
(
(
"
Recreating %s
"
%
pdfname
)
)
run_pdflatex
(
data
,
pdfname
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment