Skip to content

Commit 8e792a4

Browse files
committed
2 parents cfbbeb6 + bf60038 commit 8e792a4

10 files changed

+135
-27
lines changed

scripts/README.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Set up for class
22

3+
Many of these steps can be run together in run.sh.
4+
35
## Set up student accounts
46

57
1. Download class rosters for all sections into csv files that are put into this directory.
@@ -11,7 +13,7 @@
1113

1214
## Set up nbgrader_config.py
1315

14-
1. Generate student entries for the file with `make_student_dict_entries.py`.
16+
1. Generate student entries for the file with `make_student_dict_entries.py` and put into config file.
1517

1618

1719
## Disperse materials to students

scripts/disperse_python4geosciences_file.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# how to run:
33
# disperse_python4geosciences_file.sh [filename]
44

5-
file=$1
6-
echo copyng $file
5+
users1=$1
6+
users2=$2
7+
file=$3
78

8-
for id in `cat /root/pgs2017_g /root/pgs2017_ug` ; do
9-
cp -rf $file /d2/home/$id/notebooks/python4geosciences/materials ;
10-
chown $id:pythonspring2017 /d2/home/$id/notebooks/python4geosciences/materials/${file##*/} ;
9+
for id in `cat $users1 $users2` ; do
10+
cp -rf $file /home/$id/python4geosciences/materials ;
11+
# removes path up to the file itself
12+
chown $id:$id /home/$id/python4geosciences/materials/${file##*/} ;
1113
echo copied $file for $id
1214
done
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/bin/bash
22

3-
for id in `cat /root/pgs2017_g /root/pgs2017_ug` ; do
4-
mkdir /d2/home/$id/notebooks ;
5-
cp -rf python4geosciences /d2/home/$id/notebooks ;
6-
rm -rf /d2/home/$id/notebooks/python4geosciences/.git
7-
chown -R $id:pythonspring2017 /d2/home/$id/notebooks ;
8-
done
9-
10-
3+
users1=$1
4+
users2=$2
115

6+
for id in `cat $users1 $users2` ; do
7+
cp -rf ../../python4geosciences /home/$id ;
8+
rm -rf /home/$id/python4geosciences/.git
9+
chown -R $id:$id /home/$id ;
10+
done

scripts/email_passwords.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
f = open('passwords')
1+
import os
2+
3+
fuug = open('users_undergrads.txt')
4+
fug = open('users_grads.txt')
5+
fpug = open('passwds_undergrads.txt')
6+
fpg = open('passwds_grads.txt')
27

38
text = '''
49
Python for Geosciences
510
611
You will need a username and password to log into the computer where we will view the class materials and work on the homework assignments. The jupyter server is:
712
8-
http://redfish.tamu.edu:8000
13+
http://redfish.geos.tamu.edu:8000
914
1015
Your username (same as TAMU NetID) and password are:
1116
@@ -14,10 +19,18 @@
1419
1520
See you in class,
1621
17-
Rob
22+
Dr. Thyng
1823
'''
1924

20-
for line in f.readlines():
21-
username, password = line.split()
22-
print('{username}@email.tamu.edu'.format(username=username))
23-
print(text.format(username=username, password=password))
25+
subject = 'Python class username and password'
26+
27+
for user, passwd in zip(fuug.readlines(), fpug.readlines()):
28+
29+
# remove new line at end
30+
user = user.split()[0]
31+
passwd = passwd.split()[0]
32+
email = '{username}@email.tamu.edu'.format(username=user)
33+
message = text.format(username=user, password=passwd)
34+
# # -s is subject, email address is who to send to, after <<< is body of message
35+
command = 'mail -s "' + subject + '" ' + email + ' <<< "' + message + '"'
36+
os.system(command)

scripts/make_passwd.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
'''
2+
Generate passwords
3+
4+
Example usage:
5+
wc -l < users_undergrads.txt # count number of users
6+
python3 make_passwd.py --passwords [number of users] > passwds_undergrads.txt
7+
wc -l < users_grads.txt # count number of users
8+
python3 make_passwd.py --passwords [number of users] > passwds_grads.txt
9+
'''
10+
111
from random import shuffle
212
import argparse
313

@@ -9,8 +19,10 @@
919

1020
args = parser.parse_args()
1121

22+
23+
1224
# load in list of words
13-
f = open('../words.txt')
25+
f = open('../../wordlist.txt')
1426
words = f.readlines()
1527
f.close()
1628

scripts/make_student_dict_entries.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
'''
2+
Usage:
3+
python3 make_student_dict_entries.py undergrads.csv
4+
python3 make_student_dict_entries.py grads-600.csv
5+
python3 make_student_dict_entries.py grads-650.csv
6+
'''
7+
8+
19
import pandas as pd
210
import argparse
311

4-
parser = argparse.ArgumentParser(description='Generate random passwords based on english words.')
12+
parser = argparse.ArgumentParser(description='make student entries for nbgrader_config.py file.')
513
parser.add_argument('filename',
614
help='Name of student csv file to parse')
715
args = parser.parse_args()

scripts/make_user_account.sh

100644100755
+21-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
#!/bin/bash
22

3+
users1=$1
4+
users2=$2
5+
pass1=$3
6+
pass2=$4
37

4-
for id in `cat /root/pgs2017_g /root/pgs2017_ug` ; do
5-
adduser $id -p $password;
8+
# put users into an array
9+
users=()
10+
for id in `cat $users1 $users2` ; do
11+
users+=("$id")
12+
done
13+
# echo "${users[@]}"
14+
15+
# put passwords into an array
16+
for pass in `cat $pass1 $pass2` ; do
17+
pass+=("$pass")
18+
done
19+
20+
for ((i=0;i<${#users[@]};i++)); do
21+
# echo $i
22+
# echo ${users[$i]}
23+
# echo ${pass[$i]}
24+
sudo adduser ${users[i]} -p ${pass[i]};
625
done

scripts/parse_username.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'''
2+
Make user names
3+
24
Example usage:
3-
python parse_username.py undergrads.csv
5+
python3 parse_username.py undergrads.csv > users_undergrads.txt
6+
python3 parse_username.py grads-600.csv > users_grads.txt
7+
python3 parse_username.py grads-650.csv >> users_grads.txt
48
'''
59

610
import pandas as pd
@@ -18,4 +22,4 @@
1822
assert domain=='email.tamu.edu', 'email needs to be TAMU netID'
1923
print(username)
2024

21-
# copy and paste into a file by undergrad vs. grad to be used in disperse_...
25+
# redirect into a file by undergrad vs. grad to be used in disperse_...

scripts/remove_users.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# Oops, need to remove the user accounts I made
4+
# usage: ./remove_users.sh users_undergrads.txt users_grads.txt
5+
# also good for end of class
6+
7+
users1=$1
8+
users2=$2
9+
10+
for id in `cat $users1 $users2` ; do
11+
sudo userdel -r $id
12+
done

scripts/run.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# call your roster files undergrads.csv, grads-600.csv, and grads-650.csv.
4+
ugroster=undergrads.csv
5+
groster1=grads-600.csv
6+
groster2=grads-650.csv
7+
8+
# Save usernames
9+
python3 parse_username.py $ugroster > users_undergrads.txt
10+
python3 parse_username.py $groster1 > users_grads.txt
11+
python3 parse_username.py $groster2 >> users_grads.txt
12+
13+
# Save passwords
14+
num="$(wc -l < users_undergrads.txt)" # count number of users
15+
python3 make_passwd.py --passwords $num > passwds_undergrads.txt
16+
num="$(wc -l < users_grads.txt)" # count number of users
17+
python3 make_passwd.py --passwords $num > passwds_grads.txt
18+
19+
# Make user accounts
20+
./make_user_account.sh users_undergrads.txt users_grads.txt passwds_undergrads.txt passwds_grads.txt
21+
22+
# If you mess it up and have to start over, remove user accounts:
23+
# ./remove_users.sh users_undergrads.txt users_grads.txt
24+
25+
# Email students their username and password with `email_passwords.py`.
26+
python3 email_passwords.py
27+
28+
# Make student entries to put into nbgrader file
29+
python3 make_student_dict_entries.py $ugroster
30+
python3 make_student_dict_entries.py $groster1
31+
python3 make_student_dict_entries.py $groster2
32+
33+
# disperse class materials to students
34+
sudo ./disperse_python4geosciences_materials.sh users_undergrads.txt users_grads.txt
35+
36+
# Later, disperse another file
37+
# sudo ./disperse_python4geosciences_file.sh users_undergrads.txt users_grads.txt [filename]

0 commit comments

Comments
 (0)