fab command, to run scripts with the OpenSlides settings
Add two example scripts
This commit is contained in:
parent
3872097311
commit
9d78d44e5b
42
extras/scripts/export_list_of_speakers.py
Normal file
42
extras/scripts/export_list_of_speakers.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import csv
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# Import the openslide settings. Has has to be done before any other openslides
|
||||||
|
# import.
|
||||||
|
from openslides.main import get_user_config_path, setup_django_environment
|
||||||
|
setup_django_environment(
|
||||||
|
get_user_config_path('openslides', 'settings.py'))
|
||||||
|
|
||||||
|
from openslides.agenda.models import Speaker
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
parser = argparse.ArgumentParser(add_help=True)
|
||||||
|
parser.add_argument('-o', '--output', metavar= 'File', help='Save the output to FILE')
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
|
if args.output is None:
|
||||||
|
output = sys.stdout
|
||||||
|
else:
|
||||||
|
output = open(args.output, 'wb')
|
||||||
|
|
||||||
|
csv_writer = csv.writer(output)
|
||||||
|
csv_writer.writerow(['Item', 'Person-Name', 'Time'])
|
||||||
|
for speaker in Speaker.objects.all().order_by('item', 'weight', 'time'):
|
||||||
|
try:
|
||||||
|
time = speaker.time.strftime('%d.%m.%Y %H:%M:%S')
|
||||||
|
except AttributeError:
|
||||||
|
time = None
|
||||||
|
csv_writer.writerow([
|
||||||
|
speaker.item.title, unicode(speaker.person).encode('utf8'), time])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
66
extras/scripts/test_data.py
Normal file
66
extras/scripts/test_data.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from random import randint, choice
|
||||||
|
|
||||||
|
# Import the openslide settings. Has has to be done before any other openslides
|
||||||
|
# import.
|
||||||
|
from openslides.main import get_user_config_path, setup_django_environment
|
||||||
|
setup_django_environment(
|
||||||
|
get_user_config_path('openslides', 'settings.py'))
|
||||||
|
|
||||||
|
from openslides.participant.api import gen_username
|
||||||
|
from openslides.participant.models import User
|
||||||
|
|
||||||
|
# From jinja2
|
||||||
|
LOREM_IPSUM_WORDS = u'''\
|
||||||
|
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
|
||||||
|
auctor augue bibendum blandit class commodo condimentum congue consectetuer
|
||||||
|
consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus
|
||||||
|
diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend
|
||||||
|
elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames
|
||||||
|
faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac
|
||||||
|
hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum
|
||||||
|
justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem
|
||||||
|
luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie
|
||||||
|
mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non
|
||||||
|
nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque
|
||||||
|
penatibus per pharetra phasellus placerat platea porta porttitor posuere
|
||||||
|
potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus
|
||||||
|
ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit
|
||||||
|
sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor
|
||||||
|
tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices
|
||||||
|
ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus
|
||||||
|
viverra volutpat vulputate'''
|
||||||
|
|
||||||
|
WORDS = LOREM_IPSUM_WORDS.split(' ')
|
||||||
|
NAME_WORDS = [w for w in WORDS if not '\n' in w]
|
||||||
|
|
||||||
|
|
||||||
|
def create_names(count, func=lambda: choice(NAME_WORDS)):
|
||||||
|
"""Yields a bunch of unique names"""
|
||||||
|
used = []
|
||||||
|
for _ in xrange(count + 1):
|
||||||
|
name = func()
|
||||||
|
while name in used:
|
||||||
|
# use some random...
|
||||||
|
name = '%s%d' % (name, randint(1, count))
|
||||||
|
used.append(name)
|
||||||
|
yield name
|
||||||
|
|
||||||
|
def random_user(names):
|
||||||
|
first_name = names.next()
|
||||||
|
last_name = names.next()
|
||||||
|
return User(first_name=first_name, last_name=last_name,
|
||||||
|
username=gen_username(first_name, last_name))
|
||||||
|
|
||||||
|
|
||||||
|
def make_testdata(app=None):
|
||||||
|
if app == 'participant' or app is None:
|
||||||
|
user_count = 100
|
||||||
|
names_generator = create_names(user_count * 2)
|
||||||
|
[random_user(names_generator).save() for i in xrange(user_count)]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
make_testdata()
|
11
fabfile.py
vendored
11
fabfile.py
vendored
@ -8,6 +8,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
from fabric.api import local
|
from fabric.api import local
|
||||||
@ -68,3 +69,13 @@ def travis_ci():
|
|||||||
"""
|
"""
|
||||||
coverage_report_plain()
|
coverage_report_plain()
|
||||||
pep8()
|
pep8()
|
||||||
|
|
||||||
|
|
||||||
|
def run_script(script):
|
||||||
|
"""
|
||||||
|
Run a script with the development version of OpenSlides.
|
||||||
|
|
||||||
|
You can find some usefull scripts in extras/scrips/ in the OpenSlides repo.
|
||||||
|
"""
|
||||||
|
os.environ['PYTHONPATH'] = os.path.join(os.path.dirname(__file__))
|
||||||
|
os.system("python " + script)
|
||||||
|
@ -13,3 +13,6 @@ Fabric==1.6.0
|
|||||||
coverage==3.6
|
coverage==3.6
|
||||||
django-discover-runner==0.3
|
django-discover-runner==0.3
|
||||||
pep8==1.4.5
|
pep8==1.4.5
|
||||||
|
|
||||||
|
# For python 2.6 support
|
||||||
|
argparse==1.2.1
|
||||||
|
Loading…
Reference in New Issue
Block a user