Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
P
protokoll_skript
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
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Fachschaftsrat Physik TUKL
Protokoll
protokoll_skript
Commits
a8acf22b
Commit
a8acf22b
authored
Jan 25, 2018
by
Lorenz Steinert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_ldap working
parent
7cdc36b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
36 deletions
+81
-36
protskript_test.py
protskript_test.py
+81
-36
No files found.
protskript_test.py
View file @
a8acf22b
...
...
@@ -6,20 +6,21 @@ Created on Fri Nov 24 15:35:04 2017
@author: lorico
"""
import
ldap3
as
ldap
import
time
import
os
import
re
import
os
import
time
import
ldap3
as
ldap
try
:
import
pwd
import
pwd
except
ImportError
:
import
getpass
pwd
=
None
import
getpass
pwd
=
None
class
Protokollskript
:
"""Class die die protokoll .tex datei erstellt"""
def
current_user
(
self
):
"""get the current user"""
if
pwd
:
return
pwd
.
getpwuid
(
os
.
geteuid
()).
pw_name
else
:
...
...
@@ -47,80 +48,124 @@ class Protokollskript:
self
.
reg_A
=
re
.
compile
(
'
\"
A'
)
self
.
reg_O
=
re
.
compile
(
'
\"
O'
)
self
.
reg_U
=
re
.
compile
(
'
\"
U'
)
self
.
reg_
kov
=
re
.
compile
(
'Kovac'
)
self
.
fsr
=
[
re
.
sub
(
re
.
escape
(
'
\t
'
),
' '
,
line
.
rstrip
(
'
\n
'
))
for
line
in
open
(
'fsr'
,
'r'
).
readlines
()]
print
(
self
.
fsr
)
self
.
reg_
Kovac
=
re
.
compile
(
'Kovac'
)
self
.
fsr
=
[
re
.
sub
(
re
.
escape
(
'
\t
'
),
' '
,
line
.
rstrip
(
'
\n
'
))
for
line
in
open
(
'fsr'
,
'r'
).
readlines
()]
self
.
fsr_extern
=
[
re
.
sub
(
re
.
escape
(
'
\t
'
),
' '
,
line
.
rstrip
(
'
\n
'
))
for
line
in
open
(
'fsr_extern'
,
'r'
).
readlines
()]
def
get_protokollant_ldap
(
self
):
def
get_protokollant_ldap
(
self
,
protokollant
):
try
:
conn
=
ldap
.
Connection
(
self
.
server
)
conn
.
bind
()
#l = ldap.open(server)
#l.simple_bind_s("","")
fil
=
"(uid="
+
self
.
userid
+
")"
if
conn
.
search
(
'ou=people,'
+
self
.
base
,
fil
,
attributes
=
[
'gecos'
]):
self
.
protokollant
=
" "
.
join
(
str
(
conn
.
entries
[
0
][
'gecos'
]).
split
(
", "
)[::
-
1
])
if
conn
.
search
(
'ou=people,'
+
self
.
base
,
fil
,
attributes
=
[
'gecos'
]):
return
(
" "
.
join
(
str
(
conn
.
entries
[
0
][
'gecos'
]).
split
(
", "
)[::
-
1
]))
else
:
return
protokollant
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
print
(
"Couldn't Connect to ldap. %s "
%
error_message
)
return
protokollant
def
get_fsr_ldap
(
self
):
def
get_fsr_ldap
(
self
,
fsr
):
try
:
conn
=
ldap
.
Connection
(
self
.
server
)
conn
.
bind
()
fil
=
'(
& (cn=fsr) (!cn=extern)
)'
fil
=
'(
cn=intern
)'
fsr_
=
[]
if
conn
.
search
(
'ou=group,'
+
self
.
base
,
fil
,
attributes
=
[
'memberUid'
]):
for
i
in
conn
.
entries
[
0
][
'memberUid'
]:
if
conn
.
search
(
'ou=people,'
+
self
.
base
,
'(uid='
+
i
+
')'
,
attributes
=
[
'gecos'
]):
fsr_
+=
[
self
.
reg_
A
.
sub
(
'Ä'
,
self
.
reg_O
.
sub
(
'Ö'
,
self
.
reg_U
.
sub
(
'Ü'
,
self
.
reg_kov
.
sub
(
re
.
escape
(
'Kova
\v
{c}'
),
self
.
reg_a
.
sub
(
'ä'
,
self
.
reg_o
.
sub
(
'ö'
,
self
.
reg_u
.
sub
(
'ü'
,
str
(
conn
.
entries
[
0
][
'gecos'
]))))))))]
fsr_
+=
[
self
.
reg_
Kovac
.
sub
(
'Kova
\v
{c}'
,
self
.
reg_A
.
sub
(
'Ä'
,
self
.
reg_O
.
sub
(
'Ö'
,
self
.
reg_U
.
sub
(
'Ü'
,
self
.
reg_a
.
sub
(
'ä'
,
self
.
reg_o
.
sub
(
'ö'
,
self
.
reg_u
.
sub
(
'ü'
,
str
(
conn
.
entries
[
0
][
'gecos'
]))))))))]
fsr_
.
sort
()
fsr_
=
[
" "
.
join
(
i
.
split
(
', '
)[::
-
1
])
for
i
in
fsr_
]
self
.
fsr
=
fsr_
return
fsr_
else
:
return
fsr
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
print
(
"Couldn't Connect to ldap. %s "
%
error_message
)
return
fsr
def
get_sprecher
(
self
):
def
get_fsr_extern_ldap
(
self
,
fsr_extern
):
try
:
conn
=
ldap
.
Connection
(
self
.
server
)
conn
.
bind
()
fil
=
'(cn=extern)'
fsr_extern_
=
[]
if
conn
.
search
(
'ou=group,'
+
self
.
base
,
fil
,
attributes
=
[
'memberUid'
]):
for
i
in
conn
.
entries
[
0
][
'memberUid'
]:
if
conn
.
search
(
'ou=people,'
+
self
.
base
,
'(uid='
+
i
+
')'
,
attributes
=
[
'gecos'
]):
fsr_extern_
+=
[
self
.
reg_Kovac
.
sub
(
'Kova
\v
{c}'
,
self
.
reg_A
.
sub
(
'Ä'
,
self
.
reg_O
.
sub
(
'Ö'
,
self
.
reg_U
.
sub
(
'Ü'
,
self
.
reg_a
.
sub
(
'ä'
,
self
.
reg_o
.
sub
(
'ö'
,
self
.
reg_u
.
sub
(
'ü'
,
str
(
conn
.
entries
[
0
][
'gecos'
]))))))))]
fsr_extern_
.
sort
()
fsr_extern_
=
[
" "
.
join
(
i
.
split
(
', '
)[::
-
1
])
for
i
in
fsr_extern_
]
return
fsr_extern_
else
:
return
fsr_extern
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
print
(
"Couldn't Connect to ldap. %s "
%
error_message
)
return
fsr_extern
def
get_sprecher
(
self
,
sprecher
):
stmp
=
input
(
"Sprecher ["
+
self
.
sprecher
+
"]: "
)
if
stmp
!=
""
:
self
.
sprecher
=
stmp
return
stmp
else
:
return
sprecher
def
get_protokollant
(
self
):
def
get_protokollant
(
self
,
protokollant
):
ptmp
=
input
(
"Protokollant ["
+
self
.
protokollant
+
"]: "
)
if
ptmp
!=
""
:
self
.
protokollant
=
ptmp
return
ptmp
else
:
return
protokollant
def
get_date
(
self
):
def
get_date
(
self
,
date
):
dtmp
=
input
(
"Datum ["
+
self
.
date
+
"]: "
)
if
dtmp
!=
""
:
self
.
date
=
dtmp
return
dtmp
else
:
date
def
get_editor
(
self
):
def
get_editor
(
self
,
editor
):
etmp
=
input
(
"Editor ["
+
self
.
editor
+
"]: "
)
if
etmp
!=
""
:
self
.
editor
=
etmp
return
etmp
else
:
return
editor
def
main
(
self
):
self
.
get_protokollant_ldap
(
)
self
.
protokollant
=
self
.
get_protokollant_ldap
(
self
.
protokollant
)
print
(
"Wenn der Standardwert (in []) stimmt einfach Enter!
\n
"
)
#get data form user
self
.
get_sprecher
()
self
.
get_protokollant
()
self
.
get_date
()
self
.
get_editor
()
self
.
get_fsr_ldap
()
self
.
sprecher
=
self
.
get_sprecher
(
self
.
sprecher
)
self
.
protokollant
=
self
.
get_protokollant
(
self
.
protokollant
)
self
.
date
=
self
.
get_date
(
self
.
date
)
self
.
editor
=
self
.
get_editor
(
self
.
editor
)
self
.
fsr
=
self
.
get_fsr_ldap
(
self
.
fsr
)
self
.
fsr_extern
=
self
.
get_fsr_extern_ldap
(
self
.
fsr_extern
)
print
(
self
.
fsr
)
print
(
self
.
fsr_extern
)
outdir
=
"../"
+
str
(
self
.
year
)
+
"/fsr_physik_sitzung_"
+
str
(
self
.
year
)
+
"-"
+
str
(
self
.
mon
)
+
"-"
+
str
(
self
.
day
)
+
"/"
#os.mkdir(outdir,mode=777)
if
not
os
.
path
.
exists
(
outdir
):
os
.
makedirs
(
outdir
)
outfile
=
outdir
+
"/fsr_physik_protokoll_"
+
str
(
self
.
year
)
+
"-"
+
str
(
self
.
mon
)
+
"-"
+
str
(
self
.
day
)
+
".tex"
#daten = open('fsr','r')
#daten_ext = open('fsr_extern','r')
#head = open('head.tex','r')
#foot = open('foot.tex','r')
with
open
(
'head.tex'
,
'r'
)
as
f
:
f_head
=
f
.
read
()
with
open
(
'foot.tex'
,
'r'
)
as
f
:
f_foot
=
f
.
read
()
print
(
f_head
)
print
(
f_foot
)
#print(daten,daten_ext,head,foot)
if
__name__
==
"__main__"
:
...
...
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