Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
schildergenerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
schilder
schildergenerator
Commits
b48f7a7a
Commit
b48f7a7a
authored
Jul 31, 2015
by
Dave Kliczbor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edited signs can now be saved under the same filename they're based on.
parent
5d9788ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
48 deletions
+63
-48
schilder.py
schilder.py
+56
-48
templates/edit.html
templates/edit.html
+7
-0
No files found.
schilder.py
View file @
b48f7a7a
...
...
@@ -63,41 +63,21 @@ def check_output(*popenargs, **kwargs):
#raise Exception(output)
return
output
def
allowed_file
(
filename
):
return
'.'
in
filename
and
filename
.
rsplit
(
'.'
,
1
)[
1
]
in
config
.
allowed_extensions
@
app
.
route
(
'/'
)
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
)]
return
render_response
(
'index.html'
,
data
)
@
app
.
route
(
'/edit'
)
def
edit
(
**
kwargs
):
data
=
defaultdict
(
str
)
data
.
update
(
**
kwargs
)
imagelist
=
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
))
for
f
in
sorted
(
templatelist
)]
return
render_response
(
'edit.html'
,
data
)
@
app
.
route
(
'/edit/<filename>'
)
def
edit_one
(
filename
):
def
load_data
(
filename
):
with
open
(
os
.
path
.
join
(
config
.
datadir
,
filename
),
'r'
)
as
infile
:
formdata
=
defaultdict
(
str
,
json
.
load
(
infile
))
formdata
[
'filename'
]
=
filename
if
len
(
formdata
[
'markup'
])
<
1
:
formdata
[
'markup'
]
=
'latex'
return
edit
(
form
=
formdata
)
return
formdata
def
save_data
(
formdata
,
outfilename
):
with
open
(
os
.
path
.
join
(
config
.
datadir
,
outfilename
),
'w'
)
as
outfile
:
json
.
dump
(
formdata
,
outfile
)
def
run_pdflatex
(
context
,
outputfilename
,
overwrite
=
True
):
if
not
context
.
has_key
(
'textemplate'
):
context
[
'textemplate'
]
=
"text-image-quer.tex"
...
...
@@ -106,7 +86,6 @@ def run_pdflatex(context, outputfilename, overwrite=True):
context
[
'textemplate'
],
cls
=
NewTextTemplate
,
encoding
=
'utf8'
)
if
not
overwrite
and
os
.
path
.
isfile
(
outputfilename
)
and
os
.
path
.
getmtime
(
template
.
filepath
)
<
os
.
path
.
getmtime
(
outputfilename
):
return
print
(
str
(
context
))
if
context
[
'markup'
]
==
'rst'
:
context
[
'text'
]
=
publish_parts
(
context
[
'text'
],
writer_name
=
'latex'
)[
'body'
]
context
[
'headline'
]
=
publish_parts
(
context
[
'headline'
],
writer_name
=
'latex'
)[
'body'
]
...
...
@@ -141,18 +120,17 @@ def run_pdflatex(context, outputfilename, overwrite=True):
shutil
.
copy
(
tmppdffile
,
outputfilename
)
shutil
.
rmtree
(
tmpdir
)
def
save_and_convert_image_upload
(
inputname
):
file
=
request
.
files
[
inputname
]
if
file
:
if
not
allowed_file
(
file
.
filename
):
img
file
=
request
.
files
[
inputname
]
if
img
file
:
if
not
allowed_file
(
img
file
.
filename
):
raise
UserWarning
(
"Uploaded image is not in the list of allowed file types."
)
filename
=
os
.
path
.
join
(
config
.
uploaddir
,
secure_filename
(
file
.
filename
))
file
.
save
(
filename
)
config
.
uploaddir
,
secure_filename
(
img
file
.
filename
))
img
file
.
save
(
filename
)
img
=
PythonMagick
.
Image
(
filename
)
imgname
=
os
.
path
.
splitext
(
secure_filename
(
file
.
filename
))[
imgname
=
os
.
path
.
splitext
(
secure_filename
(
img
file
.
filename
))[
0
].
replace
(
'.'
,
'_'
)
+
'.png'
savedfilename
=
os
.
path
.
join
(
config
.
imagedir
,
imgname
)
img
.
write
(
savedfilename
)
...
...
@@ -160,6 +138,42 @@ def save_and_convert_image_upload(inputname):
return
imgname
return
None
def
make_thumb
(
filename
,
maxgeometry
):
thumbpath
=
filename
+
'.'
+
str
(
maxgeometry
)
if
not
os
.
path
.
exists
(
thumbpath
)
or
os
.
path
.
getmtime
(
filename
)
>
os
.
path
.
getmtime
(
thumbpath
):
img
=
PythonMagick
.
Image
(
str
(
filename
))
img
.
transform
(
"%sx%s"
%
(
maxgeometry
,
maxgeometry
))
img
.
quality
(
90
)
img
.
write
(
str
(
"png:%s"
%
thumbpath
))
return
thumbpath
@
app
.
route
(
'/'
)
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
)]
return
render_response
(
'index.html'
,
data
)
@
app
.
route
(
'/edit'
)
def
edit
(
**
kwargs
):
data
=
defaultdict
(
str
)
data
.
update
(
**
kwargs
)
imagelist
=
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
))
for
f
in
sorted
(
templatelist
)]
return
render_response
(
'edit.html'
,
data
)
@
app
.
route
(
'/edit/<filename>'
)
def
edit_one
(
filename
):
return
edit
(
form
=
load_data
(
filename
))
@
app
.
route
(
'/create'
,
methods
=
[
'POST'
])
def
create
():
...
...
@@ -173,10 +187,12 @@ def create():
formdata
[
'img'
]
=
imgpath
outfilename
=
secure_filename
(
formdata
[
'headline'
][:
16
])
+
str
(
hash
(
formdata
[
'headline'
]
+
formdata
[
'text'
]
+
os
.
path
.
splitext
(
formdata
[
'textemplate'
])[
0
]
+
os
.
path
.
splitext
(
formdata
[
'img'
])[
0
]))
+
'.schild'
if
formdata
[
'reusefilename'
]:
outfilename
=
secure_filename
(
formdata
[
'filename'
])
outpdfname
=
outfilename
+
'.pdf'
formdata
[
'filename'
]
=
outfilename
formdata
[
'pdfname'
]
=
outpdfname
with
open
(
os
.
path
.
join
(
config
.
datadir
,
outfilename
),
'w'
)
as
outfile
:
json
.
dump
(
formdata
,
outfile
)
save_data
(
formdata
,
outfilename
)
run_pdflatex
(
formdata
,
os
.
path
.
join
(
config
.
pdfdir
,
outpdfname
))
flash
(
Markup
(
u
"""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>"""
%
...
...
@@ -244,16 +260,6 @@ def image(imgname):
return
"Meh"
# redirect(url_for('index'))
def
make_thumb
(
filename
,
maxgeometry
):
thumbpath
=
filename
+
'.'
+
str
(
maxgeometry
)
if
not
os
.
path
.
exists
(
thumbpath
)
or
os
.
path
.
getmtime
(
filename
)
>
os
.
path
.
getmtime
(
thumbpath
):
img
=
PythonMagick
.
Image
(
str
(
filename
))
img
.
transform
(
"%sx%s"
%
(
maxgeometry
,
maxgeometry
))
img
.
quality
(
90
)
img
.
write
(
str
(
"png:%s"
%
thumbpath
))
return
thumbpath
@
app
.
route
(
'/thumbnail/<imgname>/<int:maxgeometry>'
)
def
thumbnail
(
imgname
,
maxgeometry
):
imgpath
=
os
.
path
.
join
(
config
.
imagedir
,
secure_filename
(
imgname
))
...
...
@@ -296,6 +302,8 @@ def pdfdownload(pdfname):
with
open
(
pdfpath
,
'r'
)
as
pdffile
:
return
Response
(
pdffile
.
read
(),
mimetype
=
"application/pdf"
)
if
__name__
==
'__main__'
:
app
.
debug
=
True
app
.
run
(
host
=
config
.
listen
,
port
=
config
.
port
)
templates/edit.html
View file @
b48f7a7a
...
...
@@ -15,6 +15,13 @@
<a
href=
"${ url_for('index') }"
>
Liste der fertigen Schilder
</a>
<form
method=
"post"
action=
"${ url_for('create') }"
enctype=
"multipart/form-data"
>
<py:if
test=
"defined('form') and len(form.filename) > 5"
>
<input
type=
"hidden"
name=
"filename"
value=
"${form.filename}"
/>
<div
class=
"box"
>
<input
id=
"form:reusefilename"
type=
"checkbox"
name=
"reusefilename"
/>
<label
for=
"form:reusefilename"
>
Änderungen unter gleichem Dateinamen speichern: ${form.filename}
</label>
</div>
</py:if>
<div
class=
"box"
>
<label
for=
"form:template"
>
Wähle eine TeX-Vorlage:
</label>
<ul>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment