-
Notifications
You must be signed in to change notification settings - Fork 31
Initial commit for script to create sample data on an Opencast system #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mheyen
wants to merge
10
commits into
opencast:master
Choose a base branch
from
mheyen:create_oc_testdata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ec5645f
Initial commit for script to create sample data on an Opencast system
mheyen 87a59db
The script can now generate an ingest request to create an event.
mheyen 2919d03
Added optional -f/file argument which allows to provide a path to a t…
mheyen 34e8033
Updated README
mheyen 4ebb74d
Series are now being created and more meta data was added to the events.
mheyen e047060
Added new testing video
mheyen 994f277
Split up the code into one event generation and one duplication script
mheyen ae75555
fixed format for request configuration
mheyen 2dbdbe7
Updated README
mheyen edae5d9
removed 'Umlaute' from random names
mheyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Script for duplicating events on an Opencast system | ||
|
|
||
| This script duplicates the specified Events on the Opencast system. | ||
|
|
||
| ## How to Use | ||
|
|
||
| ### Configuration | ||
|
|
||
| The script can be configured by editing the values in `config.py`: | ||
|
|
||
| | Configuration Key | Description | Default/Example | | ||
| | :------------------------ | :------------------------------------------- | :---------------------------------------- | | ||
| | `target_url` | The server URL of the target tenant | http://localhost:8080 | | ||
| | `yaml_file_path` | The path to the yaml file with the event IDs | ../create_oc_testdata/data/event_ids.yaml | | ||
| | `number_of_duplicates` | The number of duplicates per event | 2 | | ||
| | `digest_user` | The user name of the digest user | opencast_system_account | | ||
| | `digest_pw` | The password of the digest user | CHANGE_ME | | ||
|
|
||
|
|
||
| The configured digest user needs to exist on the specified Opencast system. | ||
|
|
||
| ### Usage | ||
|
|
||
| The script can be called with the following parameters (all parameters in brackets are optional): | ||
|
|
||
| `python main.py [-t TARGET_URL ] [-n NUMBER_OF_DUPLICATES ] [-f YAML_FILE_PATH]` | ||
|
|
||
| | Short Option | Long Option | Description | | ||
| | :----------: | :---------- | :----------------------------------------------- | | ||
| | `-t` | `--target` | The target url of the Opencast system | | ||
| | `-n` | `--number` | The number of duplicates to be created | | ||
| | `-f` | `--file` | The path to the file containing the event IDs | | ||
|
|
||
| #### Usage example | ||
|
|
||
| `python main.py -t localhost:8080 -n 2 -f data/event_ids.yaml` | ||
|
|
||
| ## Requirements | ||
|
|
||
| This script was written for Python 3.8. | ||
|
|
||
| It uses modules contained in the _lib_ directory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Configuration | ||
|
|
||
| # default target url for the Opencast system | ||
| target_url = "http://localhost:8080" | ||
|
|
||
| # default path to the .yaml file containing the event IDs | ||
| yaml_file_path = '../create_oc_testdata/data/event_ids.yaml' | ||
|
|
||
| # default value for the number of copies per event to be created | ||
| number_of_duplicates = 2 | ||
|
|
||
| # digest login | ||
| digest_user = "opencast_system_account" | ||
| digest_pw = "CHANGE_ME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.append(os.path.join(os.path.abspath('..'), "lib")) | ||
|
|
||
| import config | ||
| from rest_requests.request import get_request, post_request, big_post_request | ||
| from parse_args import parse_args | ||
| from args.digest_login import DigestLogin | ||
| import yaml | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Duplicate the events on a specified Opencast system | ||
| """ | ||
|
|
||
| # create digest login | ||
| digest_login = DigestLogin(user=config.digest_user, password=config.digest_pw) | ||
|
|
||
| # parse args | ||
| target_url, number_of_events, file_path = parse_args() | ||
| target_url = target_url if target_url else config.target_url | ||
| number_of_duplicates = number_of_events if number_of_events else config.number_of_duplicates | ||
| file_path = file_path if file_path else config.yaml_file_path | ||
|
|
||
| print("Starting duplication process.") | ||
|
|
||
| # test API connection | ||
| url = f'{target_url}/api/info/me' | ||
| try: | ||
| get_request(url, digest_login, "events") | ||
| except: | ||
| __abort_script("Something went wrong. No Connection to API. Stopping script. ") | ||
|
|
||
| # read IDs from file | ||
| event_ids = read_event_ids(file_path) | ||
|
|
||
| # duplicate events | ||
| url = f'{target_url}/api/workflows/' | ||
|
|
||
| for id in event_ids: | ||
| print(id) | ||
| data = { | ||
| 'event_identifier': id, | ||
| 'workflow_definition_identifier': 'duplicate-event', | ||
| 'configuration': '{"numberOfEvents":"' + str(number_of_duplicates) + '"}' | ||
| } | ||
| try: | ||
| response = post_request(url, digest_login, "events", data=data) | ||
| print(response) | ||
| except Exception as e: | ||
| print(str(e)) | ||
| __abort_script("Something went wrong. Could not duplicate event. Stopping script") | ||
|
|
||
| print("Done.") | ||
|
|
||
|
|
||
| def read_event_ids(path): | ||
| with open(path, 'r') as f: | ||
| data = yaml.safe_load(f) | ||
| return data['event-IDs'] | ||
|
|
||
|
|
||
| def __abort_script(message): | ||
| print(message) | ||
| sys.exit() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| main() | ||
| except KeyboardInterrupt: | ||
| print("\nAborting process.") | ||
| sys.exit(0) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from args.args_parser import get_args_parser | ||
| from args.args_error import args_error | ||
|
|
||
|
|
||
| MAX_NUMBER_OF_DUPLICATES = 20 | ||
|
|
||
|
|
||
| def parse_args(): | ||
| """ | ||
| Parse the arguments and check them for correctness | ||
|
|
||
| :return: target_url and number of events to be created if given | ||
| :rtype: str, int | ||
| """ | ||
| parser, optional_args, required_args = get_args_parser() | ||
|
|
||
| optional_args.add_argument("-t", "--target_url", type=str, nargs='+', help="URL of target system") | ||
| optional_args.add_argument("-n", "--number", type=int, nargs='+', help="number of duplicates per event") | ||
| optional_args.add_argument("-f", "--file", type=str, nargs='+', help="path to yaml file containing the event IDs") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| args.target_url = args.target_url if args.target_url else [None] | ||
| args.number = args.number if args.number else [None] | ||
| if args.number[0] and args.number[0] > MAX_NUMBER_OF_DUPLICATES: | ||
| args_error(parser, "too many duplicates ...") | ||
| args.file = args.file if args.file else [None] | ||
|
|
||
| return args.target_url[0], args.number[0], args.file[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Script for populating an Opencast system with test data | ||
|
|
||
| This script creates random samples of Events (and Series) on the specified Opencast system. | ||
|
|
||
| ## How to Use | ||
|
|
||
| ### Configuration | ||
|
|
||
| The script is configured by editing the values in `config.py`: | ||
|
|
||
| | Configuration Key | Description | Default/Example | | ||
| | :----------------- | :------------------------------------------ | :---------------------------------------- | | ||
| | `target_url` | The server URL of the target tenant | http://localhost:8080 | | ||
| | `test_video_path` | The path to a test video to be used | ../create_oc_testdata/data/test_video.mkv | | ||
| | `yaml_file_path` | The path to the file to store the ecent IDs | ../create_oc_testdata/data/event_ids.yaml | | ||
| | `number_of_events` | The number of Events to be created | 4 | | ||
| | `number_of_series` | The number of Series to be created | 2 | | ||
| | `digest_user` | The user name of the digest user | opencast_system_account | | ||
| | `digest_pw` | The password of the digest user | CHANGE_ME | | ||
|
|
||
|
|
||
| The configured digest user needs to exist on the specified Opencast system. | ||
|
|
||
| ### Usage | ||
|
|
||
| The script can be called with the following parameters (all parameters in brackets are optional): | ||
|
|
||
| `python main.py [-t TARGET_URL ] [-n NUMBER_OF_EVENTS ] [-f TEST_VIDEO_PATH]` | ||
|
|
||
| | Short Option | Long Option | Description | | ||
| | :----------: | :---------- | :----------------------------------------- | | ||
| | `-t` | `--target` | The target url of the Opencast system | | ||
| | `-n` | `--number` | The number of Events to be created | | ||
| | `-f` | `--file` | The path to a test video | | ||
|
|
||
| #### Usage example | ||
|
|
||
| `python main.py -t localhost:8080 -n 10 -f home/test/video.mp3` | ||
|
|
||
| ## Requirements | ||
|
|
||
| This script was written for Python 3.8. | ||
|
|
||
| It uses modules contained in the _lib_ directory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Configuration | ||
|
|
||
| # default target url for the Opencast system | ||
| target_url = "http://localhost:8080" | ||
|
|
||
| # default path to a test video | ||
| test_video_path = '../create_oc_testdata/data/test_video.mkv' | ||
| # default path where to store the event IDs | ||
| yaml_file_path = '../create_oc_testdata/data/event_ids.yaml' | ||
|
|
||
| # default value for the number of events to be created | ||
| number_of_events = 4 | ||
| # default value for the number of series to be created | ||
| number_of_series = 2 | ||
|
|
||
| # digest login | ||
| digest_user = "opencast_system_account" | ||
| digest_pw = "CHANGE_ME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| sys.path.append(os.path.join(os.path.abspath('..'), "lib")) | ||
|
|
||
| import config | ||
| from rest_requests.request import get_request, post_request, big_post_request | ||
| from parse_args import parse_args | ||
| from args.digest_login import DigestLogin | ||
| import yaml | ||
| import string | ||
| import random | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Populate the specified Opencast system with random sample events | ||
| """ | ||
|
|
||
| # create digest login | ||
| digest_login = DigestLogin(user=config.digest_user, password=config.digest_pw) | ||
|
|
||
| # parse args | ||
| target_url, number_of_events, file_path = parse_args() | ||
| target_url = target_url if target_url else config.target_url | ||
| number_of_events = number_of_events if number_of_events else config.number_of_events | ||
| file_path = file_path if file_path else config.test_video_path | ||
|
|
||
| print("Starting population process.") | ||
|
|
||
| # test API connection | ||
| url = f'{target_url}/api/info/me' | ||
| try: | ||
| get_request(url, digest_login, "events") | ||
| except: | ||
| __abort_script("Something went wrong. No Connection to API. Stopping script. ") | ||
|
|
||
| # Serien erstellen | ||
| series_ids = [] | ||
| for i in range(config.number_of_series): | ||
| url = f'{target_url}/series/' | ||
| series_id = "Series-ID-" + __generate_random_name() | ||
| series_ids.append(series_id) | ||
| data = { | ||
| 'identifier': series_id, | ||
| 'publisher': __generate_random_name(), | ||
| 'title': __generate_random_name(), | ||
| 'acl': '{"acl": {"ace": [' | ||
| '{"allow": true,"role": "ROLE_ANONYMOUS","action": "write"}, ' | ||
| '{"allow": true,"role": "ROLE_ADMIN","action": "read"}' | ||
| ']}}' | ||
| } | ||
| try: | ||
| print(post_request(url, digest_login, "series", data=data)) | ||
| except Exception as e: | ||
| print(str(e)) | ||
| __abort_script("Something went wrong. Could not create series. Stopping script") | ||
|
|
||
| # Events erstellen | ||
| event_ids = [] | ||
| url = f'{target_url}/ingest/addMediaPackage' | ||
| files = [file_path] | ||
| for i in range(number_of_events): | ||
| event_id = "ID-" + __generate_random_name(length=5) | ||
| event_ids.append(event_id) | ||
| data = { | ||
| 'creator': __generate_random_name(), | ||
| 'title': __generate_random_name(), | ||
| 'flavor': 'presentation/source', | ||
| 'description': 'This is a test description. This Event is only for testing purposes. ', | ||
| 'identifier': event_id, | ||
| 'spatial': __generate_random_name(), | ||
| 'isPartOf': random.choice(series_ids), | ||
| 'acl': '{"acl": {"ace": [' | ||
| '{"allow": true,"role": "ROLE_ADMIN","action": "read"}, ' | ||
| '{"allow": true,"role": "ROLE_ADMIN","action": "write"}' | ||
| ']}}' | ||
| } | ||
| try: | ||
| print(big_post_request(url, digest_login, "events", data=data, files=files)) | ||
| except Exception as e: | ||
| print(str(e)) | ||
| __abort_script("Something went wrong. Could not create event. Stopping script") | ||
|
|
||
| # write event IDs to yaml file | ||
| with open(config.yaml_file_path, 'w') as file: | ||
| yaml.dump({'event-IDs': event_ids}, file) | ||
|
|
||
| print("Done.") | ||
|
|
||
|
|
||
| def __create_alphabet(): | ||
| alphabet = list(string.ascii_letters) | ||
| # for i in range(10): | ||
| # alphabet.append(str(i)) | ||
| # for c in ['Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü']: | ||
| # alphabet.append(c) | ||
| return alphabet | ||
|
|
||
| alphabet = __create_alphabet() | ||
|
|
||
|
|
||
| def __generate_random_name(length=False): | ||
| name = '' | ||
| length = length if length else random.randint(1, 30) | ||
| for i in range(length): | ||
| name += random.choice(alphabet) | ||
| return name | ||
|
|
||
|
|
||
| def __abort_script(message): | ||
| print(message) | ||
| sys.exit() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| try: | ||
| main() | ||
| except KeyboardInterrupt: | ||
| print("\nAborting process.") | ||
| sys.exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from args.args_parser import get_args_parser | ||
| from args.args_error import args_error | ||
|
|
||
|
|
||
| MAX_NUMBER_OF_EVENTS = 2000 | ||
|
|
||
|
|
||
| def parse_args(): | ||
| """ | ||
| Parse the arguments and check them for correctness | ||
|
|
||
| :return: target_url and number of events to be created if given | ||
| :rtype: str, int | ||
| """ | ||
| parser, optional_args, required_args = get_args_parser() | ||
|
|
||
| optional_args.add_argument("-t", "--target_url", type=str, nargs='+', help="URL of target system") | ||
| optional_args.add_argument("-n", "--number", type=int, nargs='+', help="number of events") | ||
| optional_args.add_argument("-f", "--file", type=str, nargs='+', help="path to test file") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| args.target_url = args.target_url if args.target_url else [None] | ||
| args.number = args.number if args.number else [None] | ||
| if args.number[0] and args.number[0] > MAX_NUMBER_OF_EVENTS: | ||
| args_error(parser, "too many events ...") | ||
| args.file = args.file if args.file else [None] | ||
|
|
||
| return args.target_url[0], args.number[0], args.file[0] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has to be ../.. for the lib directory here
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it is working with
..while with../..it does not work.But I am also always calling the script via
python generate_events/main.py.