Skip to content

Commit

Permalink
Merge pull request #51 from Normo/50-pass-spotlights-path-at-runtime
Browse files Browse the repository at this point in the history
feat: pass spotlights directory path as positional argument ...
  • Loading branch information
Normo authored Mar 19, 2024
2 parents 2c84441 + 14dba4c commit fe33248
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<!--
SPDX-FileCopyrightText: 2022 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
SPDX-FileCopyrightText: 2023 Helmholtz Centre for Environmental Research (UFZ)
SPDX-License-Identifier: CC-BY-4.0
-->

# hifis.net Spotlight Migration for RSD
# Software Spotlight Migration for RSD

This repository provides a docker image to use in the RSD project to
migrate the spotlights from hifis.net into the RSD database structure.

We use Git submodules, so be sure to clone recursively or initialize the
submodules after cloning:

```bash
git clone --recurse-submodules ...
# or:
git clone ...
git submodule init
git submodule update
```
migrate the spotlights from hifis.net or any other local source into
the RSD database structure.

## Run locally

Expand All @@ -37,10 +28,13 @@ poetry install
The tool supports some command line arguments:

```shell
$ poetry run ./main.py --help
usage: main.py [OPTION]
$ poetry run ./main.py -h
usage: main.py [OPTION] PATH

Migrate Software spotlights from a local file path to the RSD.

Migrate Software spotlights from hifis.net to the RSD.
positional arguments:
PATH The file path where to find the spotlights.

options:
-h, --help show this help message and exit
Expand All @@ -54,15 +48,15 @@ options:
Define the required environment variables as specified in your RSD `frontend/.env.local`
```bash
# define database endpoint and JWT secret
export POSTGREST_URL=localhost:5432
# define POSTGREST API endpoint and JWT secret
export POSTGREST_URL=https://localhost/api/v1
export PGRST_JWT_SECRET=abcdef

# add spotlights to RSD database via PostgREST:
poetry run ./main.py
```
or import them directly from you `.env.local`:
or import them directly from your `.env.local`:
```bash
set -a
Expand Down
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
PGRST_JWT_SECRET = os.environ.get("PGRST_JWT_SECRET")
JWT_PAYLOAD = {"role": "rsd_admin"}
JWT_ALGORITHM = "HS256"
SPOTLIGHTS_DIR = "software-descriptions/software/rendered"

ORGANISATIONS = {
"Helmholtz Centre for Environmental Research (UFZ)": {
Expand Down Expand Up @@ -124,6 +123,10 @@ def get_md_without_front_matter(file):


def get_spotlights():
if not os.path.exists(SPOTLIGHTS_DIR):
logging.error("Spotlights directory %s does not exist.", SPOTLIGHTS_DIR)
raise SystemExit("Can't find Spotlights.")

files = glob.glob(SPOTLIGHTS_DIR + os.sep + "*.md")
filtered = list(filter(lambda x: "_template.md" not in x, files))

Expand Down Expand Up @@ -708,8 +711,8 @@ async def main():

def init_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Migrate Software spotlights from hifis.net to the RSD.",
usage="%(prog)s [OPTION]",
description="Migrate Software spotlights from a local file path to the RSD.",
usage="%(prog)s [OPTION] PATH",
)
parser.add_argument(
"-d",
Expand All @@ -726,6 +729,7 @@ def init_parser() -> argparse.ArgumentParser:
parser.add_argument(
"-v", "--verbose", action="store_true", help="Increase verbosity."
)
parser.add_argument("PATH", help="The file path where to find the spotlights.")
return parser


Expand All @@ -734,6 +738,7 @@ def init_parser() -> argparse.ArgumentParser:
args = mdparser.parse_args()
DELETE_SPOTLIGHTS = args.delete_all
UPDATE_IMPRINT = args.update_imprint
SPOTLIGHTS_DIR = args.PATH
if args.verbose:
logging.basicConfig(level=logging.INFO)
else:
Expand Down

0 comments on commit fe33248

Please sign in to comment.