-
Notifications
You must be signed in to change notification settings - Fork 6
/
population_script.py
59 lines (43 loc) · 1.56 KB
/
population_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
import django
django.setup()
from django.contrib.auth import get_user_model
from apps.commands.models import Command
User = get_user_model()
def populate():
user = add_user('daniel', 'gopar', 'goparman',
'gopar@gopar.com', 'password')
add_command('ls', user, 'L', '1.0',
'List all given directory contents')
add_command('git', user)
user = add_user('joey', 'gopar', 'joey',
'joey@joey.com', 'password')
add_command('tree', user, 'L', '1.0',
'List all directories in a tree structure')
add_command('rm -rf', user, 'L', note='Deletes everything \o/')
add_command('ls -alh', user, 'L', note='LISTS ALL THINGS')
def add_user(first_name, last_name, username, email, password):
user = User.objects.get_or_create(
first_name=first_name, last_name=last_name,
username=username, email=email)[0]
user.set_password(password)
user.save()
return user
def add_command(command, user, os='', version='', note=''):
command = Command.objects.get_or_create(
command=command, os=os, version=version,
note=note, user=user)[0]
command.save()
return command
def print_db():
"""
Print what we have
"""
for user in User.objects.all():
for command in user.command_set.all():
print("User: {} -- Command: {}".format(user, command))
if __name__ == '__main__':
print("Starting to populate DB...\n")
populate()
print_db()