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
8735c2d5
Commit
8735c2d5
authored
Jun 20, 2018
by
Lorenz Steinert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
beginging to move functions to own module
parent
231325f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
+134
-0
src/esme.py
src/esme.py
+134
-0
No files found.
src/esme.py
0 → 100644
View file @
8735c2d5
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 24 15:35:04 2017
@author: Lorenz Steinert
"""
import
re
import
os
import
codecs
import
ldap3
as
ldap
try
:
import
pwd
except
ImportError
:
import
getpass
pwd
=
None
def
current_user
():
"""get the current user"""
if
pwd
:
return
pwd
.
getpwuid
(
os
.
geteuid
()).
pw_name
return
getpass
.
getuser
()
class
esme
:
"""Class die die protokoll .tex datei erstellt"""
def
__init__
(
self
,
debug
,
timeout
):
self
.
debug
=
debug
self
.
server
=
ldap
.
Server
(
"rincewind.fs.physik.uni-kl.de"
,
connect_timeout
=
timeout
)
self
.
base
=
"dc=fs,dc=physik,dc=uni-kl,dc=de"
def
get_protokollant_ldap
(
self
,
protokollant
):
"""search the LDAP for the current user"""
print
(
"Fetching Protokollant from LDAP ..."
)
try
:
conn
=
ldap
.
Connection
(
self
.
server
)
conn
.
bind
()
fil
=
"(uid="
+
current_user
()
+
")"
if
conn
.
search
(
'ou=people,'
+
self
.
base
,
fil
,
attributes
=
[
'displayName'
]):
return
" "
.
join
(
str
(
conn
.
entries
[
0
][
'displayName'
]).
split
(
", "
)[::
-
1
])
return
protokollant
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
if
self
.
debug
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback default.
\n
%s
\n
"
%
error_message
)
else
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback default.
\n
"
)
return
protokollant
def
get_fsr_ldap
(
self
,
fsr
):
"""get fsr from LDAP"""
print
(
"Fetching FSR from LDAP ..."
)
try
:
conn
=
ldap
.
Connection
(
self
.
server
)
conn
.
bind
()
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
=
[
'displayName'
]):
fsr_
+=
[
str
(
conn
.
entries
[
0
][
'displayName'
])]
fsr_
.
sort
()
fsr_
=
[
" "
.
join
(
i
.
split
(
', '
)[::
-
1
])
for
i
in
fsr_
]
return
fsr_
return
fsr
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
if
self
.
debug
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback File.
\n
%s
\n
"
%
error_message
)
else
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback File.
\n
"
)
return
fsr
def
get_fsr_extern_ldap
(
self
,
fsr_extern
):
"""get the EFSR from LDAP"""
print
(
"Fetching EFSR from LDAP ..."
)
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
=
[
'displayName'
]):
fsr_extern_
+=
[
str
(
conn
.
entries
[
0
][
'displayName'
])]
fsr_extern_
.
sort
()
fsr_extern_
=
[
" "
.
join
(
i
.
split
(
', '
)[::
-
1
])
for
i
in
fsr_extern_
]
return
fsr_extern_
return
fsr_extern
except
ldap
.
core
.
exceptions
.
LDAPException
as
error_message
:
if
self
.
debug
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback File.
\n
%s
\n
"
%
error_message
)
else
:
print
(
"Couldn't Connect to ldap.
\n
Using fallback File.
\n
"
)
return
fsr_extern
def
get_sprecher
(
sprecher
):
"""get sprecher from user input"""
stmp
=
input
(
"Sprecher ["
+
sprecher
+
"]: "
)
if
stmp
!=
""
:
return
stmp
return
sprecher
def
get_protokollant
(
protokollant
):
"""get protokollant from user input"""
ptmp
=
input
(
"Protokollant ["
+
protokollant
+
"]: "
)
if
ptmp
!=
""
:
return
ptmp
return
protokollant
def
get_date
(
date
):
"""get date from user input"""
dtmp
=
input
(
"Datum ["
+
date
[
0
]
+
"]: "
)
if
dtmp
!=
""
:
day
,
mon
,
year
=
dtmp
.
split
(
'.'
)
if
len
(
mon
)
<
2
:
mon
=
"0"
+
mon
if
len
(
day
)
<
2
:
day
=
"0"
+
day
date
=
day
+
"."
+
mon
+
"."
+
year
return
(
date
,
year
,
mon
,
day
)
return
date
def
get_editor
(
editor
):
"""get the editor to use from user input"""
etmp
=
input
(
"Editor ["
+
editor
+
"]: "
)
if
etmp
!=
""
:
return
etmp
return
editor
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