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
4eaa2978
Commit
4eaa2978
authored
Jul 18, 2020
by
Dominik Woiwode
Browse files
Parse and implement folders
parent
b4a922a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
linkToPDF2.py
View file @
4eaa2978
...
...
@@ -3,7 +3,7 @@ import hashlib
import
os
from
enum
import
Enum
from
pathlib
import
Path
from
typing
import
Optional
from
typing
import
Optional
,
Dict
,
List
import
requests
...
...
@@ -74,7 +74,7 @@ class BasePad:
with
open
(
path
,
"w"
,
encoding
=
"utf-8"
)
as
d
:
d
.
write
(
content
)
def
compile
(
self
,
outFilePath
,
template
:
Template
=
None
):
def
compile
(
self
,
outFilePath
,
template
:
Template
=
None
)
->
int
:
outPath
=
Path
(
outFilePath
)
os
.
makedirs
(
outPath
.
parent
,
exist_ok
=
True
)
metadataStr
=
" "
+
" "
.
join
([
f
'-M
{
key
}
="
{
val
}
"'
for
key
,
val
in
self
.
metadata
.
items
()])
...
...
@@ -82,11 +82,12 @@ class BasePad:
if
template
is
not
None
and
template
!=
Template
.
UNDEFINED
:
templateStr
=
f
' --template="
{
template
.
fullPath
()
}
" '
cmd
=
f
'pandoc "
{
self
.
rawPath
}
"
{
metadataStr
}{
templateStr
}
-o "
{
str
(
outPath
.
absolute
())
}
"'
os
.
system
(
cmd
)
return
os
.
system
(
cmd
)
class
ProtocolPad
(
BasePad
):
def
__init__
(
self
,
source
:
SourceTypes
,
*
_
,
date
=
None
,
isFachgruppenvollversammlung
=
False
,
isApproved
=
False
):
def
__init__
(
self
,
source
:
SourceTypes
,
*
_
,
date
:
datetime
.
datetime
=
None
,
isFachgruppenvollversammlung
:
bool
=
False
,
isApproved
:
bool
=
False
):
super
().
__init__
(
source
)
self
.
date
=
date
self
.
isApproved
=
isApproved
...
...
@@ -95,39 +96,48 @@ class ProtocolPad(BasePad):
def
__repr__
(
self
):
return
super
(
ProtocolPad
,
self
).
__repr__
()[:
-
1
]
+
f
",
{
self
.
date
}
)"
def
sendMailAsApproved
(
self
):
def
sendMailAsApproved
(
self
)
->
bool
:
pass
def
sendMailAsUnapproved
(
self
):
def
sendMailAsUnapproved
(
self
)
->
bool
:
pass
def
uploadToCloud
(
self
):
def
uploadToCloud
(
self
)
->
bool
:
pass
def
uploadToGrav
(
self
):
def
uploadToGrav
(
self
)
->
bool
:
pass
class
AttachementPad
(
BasePad
):
pass
def
__init__
(
self
,
source
:
SourceTypes
,
name
:
str
,
date
:
datetime
.
datetime
=
None
,
version
=
0
,
isApproved
=
False
):
super
().
__init__
(
source
)
self
.
name
=
name
self
.
date
=
date
self
.
version
=
version
self
.
isApproved
=
isApproved
class
PadCollection
(
BasePad
):
def
__init__
(
self
,
source
:
SourceTypes
):
super
().
__init__
(
source
)
def
getPads
(
self
):
def
getPads
(
self
)
->
Dict
[
str
,
List
[
BasePad
]]
:
"""
Parsing the protocollink-Pad for urls.
"""
HTTPS
=
"https://"
pads
=
list
()
pads
=
dict
()
currentFolder
=
""
for
line
in
self
.
source
.
retrieveContent
().
split
(
"
\n
"
):
if
line
.
startswith
(
"# "
):
currentFolder
=
line
.
split
(
"#"
)[
1
].
strip
()
continue
pad
=
self
.
parsePad
(
line
)
if
pad
is
None
:
continue
pads
.
append
(
pad
)
if
currentFolder
not
in
pads
:
pads
[
currentFolder
]
=
list
()
pads
[
currentFolder
].
append
(
pad
)
return
pads
...
...
protokollGUI.py
View file @
4eaa2978
...
...
@@ -10,9 +10,8 @@ class ProtokollGUI(tk.Tk):
self
.
folders
=
dict
()
self
.
folderIndex
=
0
self
.
folders
=
{
"MainFolder"
:
self
.
rootPad
.
getPads
()
}
self
.
folders
=
self
.
rootPad
.
getPads
()
self
.
currentPads
=
list
()
self
.
topRow
=
tk
.
Frame
(
self
)
self
.
topRow
.
pack
(
fill
=
tk
.
X
,
expand
=
True
)
...
...
@@ -33,14 +32,15 @@ class ProtokollGUI(tk.Tk):
def
wrapper
(
*
args
,
**
kwargs
):
self
.
folderIndex
=
(
self
.
folderIndex
+
i
)
%
len
(
self
.
folders
)
self
.
updatePadFrame
()
return
wrapper
def
updatePadFrame
(
self
):
folderName
=
list
(
self
.
folders
.
keys
())[
self
.
folderIndex
]
self
.
folderLabel
.
configure
(
text
=
folderName
)
p
ads
=
self
.
folders
[
folderName
]
for
i
,
pad
in
enumerate
(
p
ads
):
assert
isinstance
(
pad
,
pter
.
ProtocolPad
)
self
.
currentP
ads
=
self
.
folders
[
folderName
]
for
i
,
pad
in
enumerate
(
self
.
currentP
ads
):
assert
isinstance
(
pad
,
pter
.
ProtocolPad
)
or
isinstance
(
pad
,
pter
.
AttachementPad
)
tk
.
Label
(
self
.
padFrame
,
text
=
pad
.
source
.
url
,
anchor
=
tk
.
W
,
bg
=
"red"
).
grid
(
row
=
i
,
column
=
0
,
sticky
=
tk
.
W
)
# URL
tk
.
Label
(
self
.
padFrame
,
text
=
pad
.
date
,
anchor
=
tk
.
W
,
bg
=
"blue"
).
grid
(
row
=
i
,
column
=
1
)
# Date
# Button Download
...
...
@@ -73,5 +73,6 @@ class ProtokollGUI(tk.Tk):
if
__name__
==
'__main__'
:
gui
=
ProtokollGUI
(
pter
.
LocalCache
(
"data/rootPad.md"
))
# gui = ProtokollGUI(pter.LocalCache("data/rootPad.md"))
gui
=
ProtokollGUI
(
pter
.
CodiMD
(
"https://pad.finf.uni-hannover.de/protokolllinks_terces"
))
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