aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTudor Roman2019-09-16 15:27:19 +0000
committerTudor Roman2019-09-16 15:27:19 +0000
commit76553def1d1c6145e25d029c8c10e7e7da6e942b (patch)
tree11cd5a472b315e4e06a37440962c33a44cd5ac09
parent0d00f6c129f1e308fbffcdab0b5f3804992d6cfa (diff)
downloadrmi_scripts-teste_manz.tar.gz
rmi_scripts-teste_manz.zip
backup old test machineteste_manz
-rwxr-xr-xadd_participations2
-rwxr-xr-xadd_participations_random51
-rwxr-xr-xadd_users20
-rwxr-xr-xcleanup_participation21
4 files changed, 84 insertions, 10 deletions
diff --git a/add_participations b/add_participations
index a1c5be0..98338e3 100755
--- a/add_participations
+++ b/add_participations
@@ -21,4 +21,4 @@ contest_id = sys.argv[2]
with open(sys.argv[1]) as file:
reader = csv.DictReader(file, delimiter=',')
for row in reader:
- call(['cmsAddParticipation', '-c', row['contest_id'], row['username']])
+ call(['cmsAddParticipation', '-c', contest_id, row['username']])
diff --git a/add_participations_random b/add_participations_random
new file mode 100755
index 0000000..1649d6b
--- /dev/null
+++ b/add_participations_random
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+#
+# Adds users into CMS and generate a nice table
+#
+# Made by Tudor Roman, public domain
+#
+# This script expects as its first argument a csv table with header and two columns, name and id
+# like the add_teams script. The second argument is the output csv.
+#
+
+import csv
+import sys
+import unicodedata
+import os
+import binascii
+from collections import namedtuple
+from subprocess import call
+
+def to_ascii(s):
+ return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii')
+
+if len(sys.argv) < 3:
+ print("Usage: add_participations_random <csv_in_file> <csv_out_file> [contest_id]")
+ sys.exit(1)
+
+User = namedtuple('User', 'first_name last_name username password contest_id')
+users = []
+
+with open(sys.argv[1]) as in_file:
+ reader = csv.DictReader(in_file, delimiter=',')
+ for row in reader:
+ print(row)
+ first_name = to_ascii(row['first_name'])
+ last_name = to_ascii(row['last_name'])
+ username = row['username']
+ password = binascii.b2a_hex(os.urandom(6)).decode('ascii')
+ #password = row['password']
+ if 'contest_id' in row:
+ contest_id = row['contest_id']
+ if sys.argv[3]:
+ contest_id = sys.argv[3]
+ users.append(User(first_name, last_name, username, password, contest_id))
+ with open(sys.argv[2], 'w') as out_file:
+ writer = csv.writer(out_file)
+ writer.writerow(['first_name', 'last_name', 'username', 'password', 'contest_id'])
+ for u in users:
+ writer.writerow(u)
+ for u in users:
+ print(u)
+ call(['cmsAddParticipation', '-c', u.contest_id, '-p', u.password, u.username])
+
diff --git a/add_users b/add_users
index 8396fc1..d7e4ae3 100755
--- a/add_users
+++ b/add_users
@@ -19,26 +19,28 @@ from subprocess import call
def to_ascii(s):
return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii')
-if len(sys.argv) != 3:
+if len(sys.argv) > 3:
print("Usage: add_users <csv_in_file> <csv_out_file>")
sys.exit(1)
-User = namedtuple('User', 'first_name last_name username password contest_id')
+User = namedtuple('User', 'first_name last_name username password')
users = []
with open(sys.argv[1]) as in_file:
reader = csv.DictReader(in_file, delimiter=',')
for row in reader:
+ print(row)
first_name = to_ascii(row['first_name'])
last_name = to_ascii(row['last_name'])
username = row['username']
- password = binascii.b2a_hex(os.urandom(6)).decode('ascii')
- users.append(User(first_name, last_name, username, password, row['contest_id']))
- with open(sys.argv[2], 'w') as out_file:
- writer = csv.writer(out_file)
- writer.writerow(['first_name', 'last_name', 'username', 'password', 'contest_id'])
- for u in users:
- writer.writerow(u)
+ #password = binascii.b2a_hex(os.urandom(6)).decode('ascii')
+ password = row['password']
+ users.append(User(first_name, last_name, username, password))
+# with open(sys.argv[2], 'w') as out_file:
+# writer = csv.writer(out_file)
+# writer.writerow(['first_name', 'last_name', 'username', 'password', 'contest_id'])
+# for u in users:
+# writer.writerow(u)
for u in users:
print(u)
call(['cmsAddUser', '-p', u.password, u.first_name, u.last_name, u.username])
diff --git a/cleanup_participation b/cleanup_participation
new file mode 100755
index 0000000..09231e3
--- /dev/null
+++ b/cleanup_participation
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+#
+# Deletes users from CMS
+#
+# Made by Tudor Roman, public domain
+#
+# This script expects as its first argument a table generated by add_users.
+#
+
+import csv
+import sys
+from subprocess import call
+
+if len(sys.argv) != 3:
+ print("Usage: cleanup_participation <csv_file> <contest_id>")
+ sys.exit(1)
+
+with open(sys.argv[1]) as file:
+ reader = csv.DictReader(file, delimiter=',')
+ for row in reader:
+ call(['cmsRemoveParticipation', row['username'], '-c', sys.argv[2]])