Skip to content
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

ufal/py-update-license-definition-url-according-to-repository-path #113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ debug.log.txt
clarin-dspace-dump-8.8.23

# data folders
.data/
.temp-files/
data/
temp-files/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ Update `const.py`
- `CLARIN_DSPACE_7_PORT = 5432`
- `CLARIN_DSPACE_7_USER = "<USERNAME>"`
- `CLARIN_DSPACE_7_PASSWORD = "<PASSWORD>"`
#### const - for importing licenses
- `OLD_LICENSE_DEFINITION_STRING = <OLD_SITE_URL>`
- `NEW_LICENSE_DEFINITION_STRING = <NEW_SITE_URL>`

**NOTE:** Be sure, that `authorization = True`, because some of the used endpoints won't work

Expand Down
6 changes: 6 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
CLARIN_DSPACE_7_USER = "<USERNAME>"
CLARIN_DSPACE_7_PASSWORD = "<PASSWORD>"

# IMPORTING LICENSES
# String which should be replaced
OLD_LICENSE_DEFINITION_STRING = 'https://lindat.mff.cuni.cz/repository/xmlui/page/'
# String which will be replaced instead of OLD_LICENSE_DEFINITION_STRING
NEW_LICENSE_DEFINITION_STRING = FE_url + '/static/'


class ItemType(enum.Enum):
ITEM = 1
Expand Down
20 changes: 17 additions & 3 deletions data_pump/license.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
import os

from const import OLD_LICENSE_DEFINITION_STRING, NEW_LICENSE_DEFINITION_STRING
from migration_const import ICON_PATH
from data_pump.utils import read_json, do_api_post, convert_response_to_json, \
save_dict_as_json
from data_pump.utils import read_json, do_api_post, convert_response_to_json


def import_license(eperson_id_dict, statistics_dict):
Expand Down Expand Up @@ -77,7 +77,7 @@ def import_license(eperson_id_dict, statistics_dict):
for license_ in license_json_list:
license_json_p = {
'name': license_['name'],
'definition': license_['definition'],
'definition': update_license_definition(license_['definition']),
'confirmation': license_['confirmation'],
'requiredInfo': license_['required_info'],
'clarinLicenseLabel': labels_dict[license_['label_id']]
Expand All @@ -100,3 +100,17 @@ def import_license(eperson_id_dict, statistics_dict):
statistics_dict['license_definition'] = statistics_val
logging.info("License_label, Extended_mapping, License_definitions "
"were successfully imported!")


def update_license_definition(current_license_definition: str):
"""
Replace license definition url from current site url to a new site url
e.g., from `https://lindat.mff.cuni.cz/repository/xmlui/page/licence-hamledt`
to `https://lindat.mff.cuni.cz/repository/static/licence-hamledt.html`
"""
# Replace old site url to a new site url
new_license_definition = current_license_definition.replace(OLD_LICENSE_DEFINITION_STRING,
NEW_LICENSE_DEFINITION_STRING)
# File name has a missing `.html` suffix -> add that suffix to the end of the definition url
new_license_definition = new_license_definition + '.html'
return new_license_definition
2 changes: 1 addition & 1 deletion migration_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# mapping dict names
EPERSON_DICT = "eperson_dict.json"
USER_REGISTRATION_DICT = "user_registration_dict.json"
EPERSONGROUP_DICT = "ersongroup_dict.json"
EPERSONGROUP_DICT = "epersongroup_dict.json"
COMMUNITY_DICT = "community_dict.json"
COLLECTION_DICT = "collection_dict.json"
ITEM_DICT = "item_dict.json"
Expand Down