Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Roman Karwacik
website
Commits
e8802537
Commit
e8802537
authored
Oct 15, 2017
by
Andreas Valder
Browse files
moved scheduler related stuff to scheduler.py, moved some more parts to template_helper.py
parent
570430ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
scheduler.py
0 → 100644
View file @
e8802537
from
server
import
*
import
threading
import
sched
scheduler
=
sched
.
scheduler
()
def
run_scheduler
():
time
.
sleep
(
1
)
# UWSGI does weird things on startup
while
True
:
scheduler
.
run
()
time
.
sleep
(
10
)
def
sched_func
(
delay
,
priority
=
0
,
firstdelay
=
None
,
args
=
[],
kargs
=
{}):
if
firstdelay
==
None
:
firstdelay
=
random
.
randint
(
1
,
120
)
def
wrapper
(
func
):
def
sched_wrapper
():
with
app
.
test_request_context
():
try
:
func
(
*
args
,
**
kargs
)
except
Exception
:
traceback
.
print_exc
()
scheduler
.
enter
(
delay
,
priority
,
sched_wrapper
)
scheduler
.
enter
(
firstdelay
,
priority
,
sched_wrapper
)
return
func
return
wrapper
threading
.
Thread
(
target
=
run_scheduler
,
daemon
=
True
).
start
()
server.py
View file @
e8802537
...
...
@@ -2,12 +2,10 @@ from flask import Flask, g, request, url_for, redirect, session, render_template
from
werkzeug.routing
import
Rule
from
functools
import
wraps
from
datetime
import
date
,
timedelta
,
datetime
,
time
,
MINYEAR
import
threading
import
os
import
sys
import
hashlib
import
random
import
sched
import
traceback
import
string
from
socket
import
gethostname
...
...
@@ -16,46 +14,12 @@ import math
import
locale
import
base64
import
json
import
time
locale
.
setlocale
(
locale
.
LC_ALL
,
'de_DE.utf8'
)
app
=
Flask
(
__name__
)
app
.
jinja_env
.
trim_blocks
=
True
app
.
jinja_env
.
lstrip_blocks
=
True
app
.
add_template_global
(
random
.
randint
,
name
=
'randint'
)
app
.
add_template_global
(
datetime
,
name
=
'datetime'
)
app
.
add_template_global
(
timedelta
,
name
=
'timedelta'
)
app
.
add_template_global
(
gethostname
,
name
=
'gethostname'
)
app
.
add_template_global
(
min
,
name
=
'min'
)
app
.
add_template_global
(
max
,
name
=
'max'
)
scheduler
=
sched
.
scheduler
()
def
run_scheduler
():
import
time
time
.
sleep
(
1
)
# UWSGI does weird things on startup
while
True
:
scheduler
.
run
()
time
.
sleep
(
10
)
def
sched_func
(
delay
,
priority
=
0
,
firstdelay
=
None
,
args
=
[],
kargs
=
{}):
if
firstdelay
==
None
:
firstdelay
=
random
.
randint
(
1
,
120
)
def
wrapper
(
func
):
def
sched_wrapper
():
with
app
.
test_request_context
():
try
:
func
(
*
args
,
**
kargs
)
except
Exception
:
traceback
.
print_exc
()
scheduler
.
enter
(
delay
,
priority
,
sched_wrapper
)
scheduler
.
enter
(
firstdelay
,
priority
,
sched_wrapper
)
return
func
return
wrapper
threading
.
Thread
(
target
=
run_scheduler
,
daemon
=
True
).
start
()
config
=
app
.
config
config
.
from_pyfile
(
'config.py.example'
,
silent
=
True
)
if
sys
.
argv
[
0
].
endswith
(
'run.py'
):
...
...
@@ -65,17 +29,13 @@ config.from_pyfile('config.py', silent=True)
if
config
[
'DEBUG'
]:
app
.
jinja_env
.
auto_reload
=
True
# get git commit
import
subprocess
output
=
subprocess
.
check_output
([
'git'
,
"log"
,
"-g"
,
"-1"
,
"--pretty=%H # %h # %d # %s"
]).
decode
(
'UTF-8'
).
split
(
'#'
,
3
)
app
.
jinja_env
.
globals
[
'gitversion'
]
=
{
'hash'
:
output
[
1
],
'longhash'
:
output
[
0
],
'branch'
:
output
[
2
],
'msg'
:
output
[
3
]
}
if
not
config
.
get
(
'SECRET_KEY'
,
None
):
config
[
'SECRET_KEY'
]
=
os
.
urandom
(
24
)
from
db
import
query
,
modify
,
show
,
searchquery
from
ldap
import
ldapauth
from
legacy
import
legacy_index
from
scheduler
import
sched_func
mod_endpoints
=
[]
...
...
template_helper.py
View file @
e8802537
from
server
import
*
import
subprocess
app
.
jinja_env
.
trim_blocks
=
True
app
.
jinja_env
.
lstrip_blocks
=
True
app
.
add_template_global
(
random
.
randint
,
name
=
'randint'
)
app
.
add_template_global
(
datetime
,
name
=
'datetime'
)
app
.
add_template_global
(
timedelta
,
name
=
'timedelta'
)
app
.
add_template_global
(
gethostname
,
name
=
'gethostname'
)
app
.
add_template_global
(
min
,
name
=
'min'
)
app
.
add_template_global
(
max
,
name
=
'max'
)
# get git commit
output
=
subprocess
.
check_output
([
'git'
,
"log"
,
"-g"
,
"-1"
,
"--pretty=%H # %h # %d # %s"
]).
decode
(
'UTF-8'
).
split
(
'#'
,
3
)
app
.
jinja_env
.
globals
[
'gitversion'
]
=
{
'hash'
:
output
[
1
],
'longhash'
:
output
[
0
],
'branch'
:
output
[
2
],
'msg'
:
output
[
3
]
}
@
app
.
template_global
()
def
ismod
(
*
args
):
...
...
Write
Preview
Supports
Markdown
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