Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Fachrat Informatik
pter
Commits
50bf8f3d
Commit
50bf8f3d
authored
Nov 25, 2020
by
dwoiwode
Browse files
Fix Merge error and further style cleanup
parent
18082c41
Changes
2
Hide whitespace changes
Inline
Side-by-side
linkToPDF2.py
View file @
50bf8f3d
import
datetime
import
hashlib
import
os
import
subprocess
from
dataclasses
import
dataclass
...
...
@@ -9,9 +8,9 @@ from typing import Optional, Dict, List, Iterator, Tuple
import
requests
import
config
from
pterClasses
import
Gremium
,
GREMIUM_FR
,
GREMIUM_FSR
,
MailParticipant
,
sendFRMail
,
SemesterPart
from
pterClasses
import
Gremium
,
GREMIUM_FR
,
GREMIUM_FSR
,
MailParticipant
,
send_fr_mail
,
SemesterPart
import
config
opt
=
config
.
Config
()
...
...
@@ -22,7 +21,8 @@ class Semester:
def
__post_init__
(
self
):
self
.
display_name
=
f
"
{
self
.
part
.
value
}
{
self
.
year
}
"
self
.
grav_path
=
Path
(
opt
.
GIT_REPO_PATH
)
/
opt
.
GRAV_PROTOCOL_PATH
/
self
.
_grav_name
()
/
"protocol_semester.de.md"
self
.
grav_path
=
Path
(
opt
.
GIT_REPO_PATH
)
/
opt
.
GRAV_PROTOCOL_PATH
/
self
.
_grav_name
()
/
"protocol_semester.de.md"
def
_grav_name
(
self
):
return
f
"
{
self
.
year
-
2000
}{
self
.
part
.
short
()
}
"
...
...
@@ -150,15 +150,15 @@ class BasePad:
return
self
.
source
.
url
@
property
def
raw
P
ath
(
self
)
->
Path
:
def
raw
_p
ath
(
self
)
->
Path
:
return
Path
(
opt
.
DATA_FOLDER
).
absolute
()
/
"raw"
/
f
"
{
self
.
display_name
}
.md"
@
property
def
compiled
P
ath
(
self
)
->
Path
:
def
compiled
_p
ath
(
self
)
->
Path
:
return
Path
(
opt
.
DATA_FOLDER
).
absolute
()
/
"result"
/
f
"
{
self
.
display_name
}
.pdf"
def
download
(
self
,
override
=
True
):
content
=
self
.
source
.
retrieve
C
ontent
()
content
=
self
.
source
.
retrieve
_c
ontent
()
if
not
override
and
self
.
raw_path
.
exists
():
raise
FileExistsError
(
f
"
{
self
.
raw_path
}
already exists!"
)
self
.
raw_path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
...
...
@@ -166,9 +166,8 @@ class BasePad:
d
.
write
(
content
)
self
.
source
=
LocalCache
(
self
.
source
.
url
,
str
(
self
.
raw_path
))
def
compile
(
self
,
template
:
str
=
None
)
->
int
:
self
.
compiledPath
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
def
compile_
(
self
,
template
:
str
=
None
)
->
int
:
self
.
compiled_path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
metadata
=
[
f
'-M
{
key
}
="
{
val
}
"'
for
key
,
val
in
self
.
metadata
.
items
()]
if
template
is
None
and
hasattr
(
self
,
"gremium"
):
template
=
getattr
(
self
,
"gremium"
).
full_template
()
...
...
@@ -211,15 +210,15 @@ class ProtocolPad(BasePad):
# TODO: better top filter?
lines
=
self
.
source
.
retrieve_content
().
split
(
"
\n
"
)
tops
=
[]
for
l
in
lines
:
for
l
ine
in
lines
:
# TODO: Change to regex?
# import re
# res = re.match("^## ([\w\d &!\"'§$%/\-+äöüß]+)\w*(\(\d\d:\d\d Uhr\))?", l)
# res = re.match("^## ([\w\d &!\"'§$%/\-+äöüß]+)\w*(\(\d\d:\d\d Uhr\))?", l
ine
)
# if res is not None:
# top = res.group(1)
if
l
.
startswith
(
"## "
):
top
=
l
.
strip
(
"#"
).
rsplit
(
"("
)[
0
].
strip
()
if
l
ine
.
startswith
(
"## "
):
top
=
l
ine
.
strip
(
"#"
).
rsplit
(
"("
)[
0
].
strip
()
if
any
(
top
in
t
or
t
in
top
for
t
in
opt
.
IGNORED_TOPS
):
continue
tops
.
append
(
top
)
...
...
@@ -228,18 +227,18 @@ class ProtocolPad(BasePad):
def
cleaned_raw
(
self
):
lines_new
=
[]
ignore
=
False
for
l
in
self
.
source
.
retrieve_content
().
split
(
"
\n
"
):
if
l
.
startswith
(
"######"
):
# tags 'fr'
for
l
ine
in
self
.
source
.
retrieve_content
().
split
(
"
\n
"
):
if
l
ine
.
startswith
(
"######"
):
# tags 'fr'
continue
if
l
==
"---"
:
if
l
ine
==
"---"
:
ignore
=
True
continue
if
l
==
"..."
:
if
l
ine
==
"..."
:
ignore
=
False
continue
if
ignore
:
continue
lines_new
.
append
(
l
)
lines_new
.
append
(
l
ine
)
return
"
\n
"
.
join
(
lines_new
)
def
send_mail_as_preliminary
(
self
)
->
bool
:
...
...
@@ -391,12 +390,12 @@ class PadCollection(BasePad):
url
=
f
"https://
{
url
}
"
.
strip
()
if
Etherpad
.
fit_url
(
url
):
retrieve
C
lass
=
CachedEtherPad
retrieve
_c
lass
=
CachedEtherPad
elif
CodiMD
.
fit_url
(
url
):
retrieve
C
lass
=
CachedCodiMD
retrieve
_c
lass
=
CachedCodiMD
else
:
raise
ValueError
(
"Cannot retrieve SourceType class"
)
src
=
retrieve
C
lass
(
url
)
src
=
retrieve
_c
lass
(
url
)
is_attachement
=
opt
.
ATTACHMENT_SIGN
in
all_prefixes
is_fachgrupenvollversammlung
=
opt
.
FACHGRUPPENVOLLVERSAMMLUNG_SIGN
in
all_prefixes
...
...
@@ -404,24 +403,24 @@ class PadCollection(BasePad):
kwargs
=
dict
()
if
is_attachement
:
pad
T
ype
=
AttachementPad
pad
_t
ype
=
AttachementPad
kwargs
[
"date"
]
=
None
kwargs
[
"name"
]
=
None
kwargs
[
"version"
]
=
None
kwargs
[
"is_approved"
]
=
is_approved
else
:
pad
T
ype
=
ProtocolPad
pad
_t
ype
=
ProtocolPad
kwargs
[
"is_approved"
]
=
is_approved
try
:
date
=
datetime
.
datetime
.
strptime
(
comment
[
0
].
strip
(),
"%d.%m.%Y"
)
except
Exception
:
date
S
tr
=
url
.
split
(
"protokoll"
)[
-
1
][:
8
]
date
=
datetime
.
datetime
.
strptime
(
date
S
tr
,
"%Y%m%d"
)
date
_s
tr
=
url
.
split
(
"protokoll"
)[
-
1
][:
8
]
date
=
datetime
.
datetime
.
strptime
(
date
_s
tr
,
"%Y%m%d"
)
kwargs
[
"date"
]
=
date
kwargs
[
"is_fachgruppenvollversammlung"
]
=
is_fachgrupenvollversammlung
return
pad
T
ype
(
src
,
**
kwargs
)
return
pad
_t
ype
(
src
,
**
kwargs
)
def
remove_approved
(
self
):
old_pads
=
self
.
pads
...
...
@@ -452,16 +451,15 @@ class PadCollection(BasePad):
def
compile_pads
(
self
,
template
:
str
=
None
):
for
folder
,
pad
in
self
:
pad
.
compile
(
template
)
pad
.
compile
_
(
template
)
def
create_topics
(
self
):
raise
NotImplementedError
()
if
__name__
==
'__
main
__'
:
def
main
()
:
import
argparse
opt
=
config
.
Config
()
parser
=
argparse
.
ArgumentParser
(
description
=
"Download and convert finf/fsr-protocols using pandoc"
)
parser
.
add_argument
(
"-urls"
,
nargs
=
"+"
,
type
=
str
,
default
=
[])
...
...
@@ -515,3 +513,7 @@ if __name__ == '__main__':
if
parsed
.
compile
:
pads
.
compile_pads
()
if
__name__
==
'__main__'
:
main
()
protokollGUI.py
View file @
50bf8f3d
...
...
@@ -6,7 +6,7 @@ import linkToPDF2 as pter
import
pterClasses
class
Proto
kol
lGUI
(
tk
.
Tk
):
class
Proto
co
lGUI
(
tk
.
Tk
):
def
__init__
(
self
,
opt
:
config
.
Config
):
super
().
__init__
(
screenName
=
"ProtokollHelper"
)
self
.
opt
=
opt
...
...
@@ -34,16 +34,16 @@ class ProtokollGUI(tk.Tk):
def
update_folder_index
(
self
,
i
):
@
wraps
(
self
.
update_folder_index
)
def
wrapper
(
*
args
,
**
kwargs
):
def
wrapper
(
*
_
,
**
__
):
self
.
folder_index
=
(
self
.
folder_index
+
i
)
%
len
(
self
.
folders
)
self
.
update_pad_frame
()
return
wrapper
def
update_pad_frame
(
self
):
folder
N
ame
=
list
(
self
.
folders
.
keys
())[
self
.
folder_index
]
self
.
folder_label
.
configure
(
text
=
folder
N
ame
)
self
.
current_pads
=
[
p
for
p
in
self
.
folders
[
folder
N
ame
]
if
isinstance
(
p
,
pter
.
ProtocolPad
)]
folder
_n
ame
=
list
(
self
.
folders
.
keys
())[
self
.
folder_index
]
self
.
folder_label
.
configure
(
text
=
folder
_n
ame
)
self
.
current_pads
=
[
p
for
p
in
self
.
folders
[
folder
_n
ame
]
if
isinstance
(
p
,
pter
.
ProtocolPad
)]
for
i
,
pad
in
enumerate
(
self
.
current_pads
):
assert
isinstance
(
pad
,
pter
.
ProtocolPad
)
approved_state
=
tk
.
NORMAL
if
pad
.
is_approved
else
tk
.
DISABLED
...
...
@@ -57,7 +57,7 @@ class ProtokollGUI(tk.Tk):
# Button Compile
btn_compile
=
tk
.
Button
(
self
.
pad_frame
,
text
=
"Compile"
,
command
=
pad
.
compile
)
command
=
pad
.
compile
_
)
btn_compile
.
grid
(
row
=
i
,
column
=
3
)
# Button Mail FR
...
...
@@ -67,7 +67,7 @@ class ProtokollGUI(tk.Tk):
# Button Mail FR-Info
btn_mail_fr_info
=
tk
.
Button
(
self
.
pad_frame
,
text
=
"FR-Info Mail"
,
state
=
approved_state
,
bg
=
color
,
command
=
pad
.
send_mail_as_approved
)
command
=
pad
.
send_mail_as_approved
)
btn_mail_fr_info
.
grid
(
row
=
i
,
column
=
5
)
# Button Website
...
...
@@ -83,5 +83,5 @@ class ProtokollGUI(tk.Tk):
if
__name__
==
'__main__'
:
pter
.
opt
.
GREMIUM
=
pterClasses
.
GREMIUM_FR
gui
=
Proto
kol
lGUI
(
pter
.
opt
)
gui
=
Proto
co
lGUI
(
pter
.
opt
)
gui
.
mainloop
()
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