Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grady
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Maximilian Michal
grady
Commits
b6a3c271
Commit
b6a3c271
authored
7 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
Small changes
parent
7e98b964
No related branches found
Branches containing commit
No related tags found
1 merge request
!3
Resolve "New input format"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
grrr.py
+48
-11
48 additions, 11 deletions
grrr.py
with
50 additions
and
11 deletions
.gitignore
+
2
−
0
View file @
b6a3c271
...
@@ -21,6 +21,8 @@ build/
...
@@ -21,6 +21,8 @@ build/
static/
static/
tests/report/
tests/report/
*.sqlite3
*.sqlite3
env/
static/
# project specific
# project specific
env-grady/
env-grady/
...
...
This diff is collapsed.
Click to expand it.
grrr.py
+
48
−
11
View file @
b6a3c271
...
@@ -4,6 +4,7 @@ import os
...
@@ -4,6 +4,7 @@ import os
os
.
environ
.
setdefault
(
'
DJANGO_SETTINGS_MODULE
'
,
'
grady.settings
'
)
os
.
environ
.
setdefault
(
'
DJANGO_SETTINGS_MODULE
'
,
'
grady.settings
'
)
import
secrets
import
secrets
import
sys
import
sys
import
json
import
django
import
django
django
.
setup
()
django
.
setup
()
...
@@ -25,6 +26,20 @@ def parseme():
...
@@ -25,6 +26,20 @@ def parseme():
'
newstudentpasswordlist
'
,
'
newstudentpasswordlist
'
,
help
=
'
all student passwords will be changed and a list of these password will be printed
'
help
=
'
all student passwords will be changed and a list of these password will be printed
'
)
)
newstudentpasswordlist
.
add_argument
(
'
instance
'
,
help
=
'
name of the instance that generated the passwords
'
)
replaceusernames
=
subparsers
.
add_parser
(
'
replaceusernames
'
,
help
=
'
replaces all usernames based on a matrikel_no -> new_name dict (input should be JSON)
'
)
replaceusernames
.
add_argument
(
'
matno2username_dict
'
,
help
=
'
the mapping as a JSON file
'
,
type
=
argparse
.
FileType
(
'
r
'
)
)
enableusers
=
subparsers
.
add_parser
(
enableusers
=
subparsers
.
add_parser
(
'
enableusers
'
,
'
enableusers
'
,
...
@@ -36,12 +51,18 @@ def parseme():
...
@@ -36,12 +51,18 @@ def parseme():
default
=
'
on
'
,
default
=
'
on
'
,
help
=
'
enable all users (on) or disable all (off)
'
help
=
'
enable all users (on) or disable all (off)
'
)
)
enableusers
.
add_argument
(
filter_group
=
enableusers
.
add_mutually_exclusive_group
()
filter_group
.
add_argument
(
'
-e
'
,
'
--exclude
'
,
'
-e
'
,
'
--exclude
'
,
default
=
(),
default
=
(),
nargs
=
'
+
'
,
nargs
=
'
+
'
,
help
=
'
give exceptions by username in a comma separated list
'
help
=
'
give exceptions by username in a comma separated list
'
)
)
filter_group
.
add_argument
(
'
-i
'
,
'
--include
'
,
help
=
'
only apply to these users
'
,
nargs
=
'
+
'
,
default
=
())
parser
.
add_argument
(
parser
.
add_argument
(
'
-o
'
,
'
--output
'
,
'
-o
'
,
'
--output
'
,
...
@@ -53,12 +74,12 @@ def parseme():
...
@@ -53,12 +74,12 @@ def parseme():
return
parser
.
parse_args
()
return
parser
.
parse_args
()
def
handle_newstudentpasswordlist
(
output
=
sys
.
stdout
):
def
handle_newstudentpasswordlist
(
output
=
sys
.
stdout
,
instance
=
""
):
with
open
(
'
/usr/share/dict/words
'
)
as
words
:
with
open
(
'
/usr/share/dict/words
'
)
as
words
:
choose_from
=
list
({
word
.
strip
().
lower
()
for
word
in
words
if
5
<
len
(
word
)
<
8
})
choose_from
=
list
({
word
.
strip
().
lower
()
for
word
in
words
if
5
<
len
(
word
)
<
8
})
print
(
len
(
choose_from
))
writer
=
csv
.
writer
(
output
)
writer
=
csv
.
writer
(
output
)
writer
.
writerow
([
'
Name
'
,
'
Matrikel
'
,
'
Username
'
,
'
password
'
,
'
instance
'
])
for
student
in
Student
.
objects
.
all
():
for
student
in
Student
.
objects
.
all
():
password
=
''
.
join
(
secrets
.
choice
(
choose_from
)
for
_
in
range
(
3
))
password
=
''
.
join
(
secrets
.
choice
(
choose_from
)
for
_
in
range
(
3
))
...
@@ -67,21 +88,37 @@ def handle_newstudentpasswordlist(output=sys.stdout):
...
@@ -67,21 +88,37 @@ def handle_newstudentpasswordlist(output=sys.stdout):
student
.
user
.
save
()
student
.
user
.
save
()
writer
.
writerow
([
student
.
name
,
student
.
matrikel_no
,
writer
.
writerow
([
student
.
name
,
student
.
matrikel_no
,
student
.
user
.
username
,
password
])
student
.
user
.
username
,
password
,
instance
])
def
handle_enableusers
(
switch
,
exclude
,
include
):
if
include
:
for
user
in
User
.
objects
.
filter
(
username__in
=
include
):
user
.
is_active
=
switch
==
'
on
'
user
.
save
()
else
:
# this includes nothing set
for
user
in
User
.
objects
.
exclude
(
username__in
=
exclude
):
user
.
is_active
=
switch
==
'
on
'
user
.
save
()
def
handle_enableusers
(
switch
,
exclude
):
for
user
in
User
.
objects
.
exclude
(
username__in
=
exclude
):
def
handle_replace_usernames
(
matno2username
):
user
.
is_active
=
switch
==
'
off
'
for
student
in
Student
.
objects
.
all
():
user
.
save
()
if
student
.
matrikel_no
in
matno2username
:
new_name
=
matno2username
[
student
.
matrikel_no
]
student
.
user
.
username
=
new_name
student
.
user
.
save
()
def
main
():
def
main
():
args
=
parseme
()
args
=
parseme
()
if
args
.
command
==
'
newstudentpasswordlist
'
:
if
args
.
command
==
'
newstudentpasswordlist
'
:
handle_newstudentpasswordlist
(
args
.
output
)
handle_newstudentpasswordlist
(
args
.
output
,
args
.
instance
)
elif
args
.
command
==
'
enableusers
'
:
if
args
.
command
==
'
enableusers
'
:
handle_enableusers
(
args
.
switch
,
args
.
exclude
)
handle_enableusers
(
args
.
switch
,
args
.
exclude
,
args
.
include
)
if
args
.
command
==
'
replaceusernames
'
:
handle_replace_usernames
(
json
.
JSONDecoder
().
decode
(
args
.
matno2username_dict
.
read
()))
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
()
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment