Skip to content

Commit aade1ab

Browse files
committed
Merge branch 'main' of github.com:UW-Macrostrat/macrostrat
2 parents c6c9bf9 + b63b1d1 commit aade1ab

File tree

2 files changed

+150
-70
lines changed

2 files changed

+150
-70
lines changed

map-integration/macrostrat/map_integration/__init__.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
os.environ["USE_PYGEOS"] = "0"
66

77
import re
8+
from pathlib import Path
89
from sys import stdin
910

1011
from psycopg2.sql import Identifier
12+
from rich.console import Console
1113
from typer import Option
1214

1315
from macrostrat.core import app
@@ -17,6 +19,7 @@
1719
from macrostrat.map_integration.process.geometry import create_rgeom, create_webgeom
1820
from macrostrat.map_integration.utils.file_discovery import find_gis_files
1921
from macrostrat.map_integration.utils.map_info import get_map_info
22+
from macrostrat.map_integration.utils.staging_upload_dir import *
2023

2124
from . import pipeline
2225
from .commands.copy_sources import copy_macrostrat_sources
@@ -28,23 +31,19 @@
2831
from .commands.sources import map_sources
2932
from .database import get_database
3033
from .migrations import run_migrations
34+
from .pipeline import upload_file
3135
from .process import cli as _process
3236
from .process.insert import _delete_map_data
3337
from .utils import IngestionCLI, MapInfo, table_exists
34-
from rich.console import Console
35-
36-
from pathlib import Path
37-
from .pipeline import upload_file
38-
from macrostrat.map_integration.utils.file_discovery import find_gis_files
39-
from macrostrat.map_integration.utils.staging_upload_dir import *
4038

4139
help_text = f"""Ingest maps into Macrostrat.
4240
4341
Active map: [bold cyan]{app.state.get("active_map")}[/]
4442
"""
45-
console =Console()
43+
console = Console()
4644
cli = IngestionCLI(no_args_is_help=True, name="map-ingestion", help=help_text)
4745

46+
4847
@cli.command(name="set-active")
4948
def set_active_map(map: MapInfo = None):
5049
"""Set the active map for the current session."""
@@ -256,6 +255,7 @@ def _run_migrations(database: str = None):
256255
staging_cli = IngestionCLI(no_args_is_help=True, help="Staging pipeline & storage")
257256
cli.add_typer(staging_cli, name="staging")
258257

258+
259259
def staging(
260260
slug: str,
261261
data_path: str,
@@ -382,11 +382,13 @@ def staging(
382382
f"\nFinished staging setup for {slug}. View map here: https://dev.macrostrat.org/maps/ingestion/{source_id}/ \n"
383383
)
384384

385+
385386
staging_cli.add_command(staging, name="ingest")
386387

387-
#------------------------------------------
388+
# ------------------------------------------
388389
# commands nested under 'macrostrat maps staging...'
389390

391+
390392
@staging_cli.command("upload-dir")
391393
def cmd_upload_dir(
392394
slug: str = ...,
@@ -395,40 +397,52 @@ def cmd_upload_dir(
395397
"""Upload a local directory to the staging bucket under SLUG/."""
396398
res = staging_upload_dir(slug, data_path)
397399
pretty_res = json.dumps(res, indent=2)
398-
console.print(f'[green] Upload successful! \n {pretty_res} [/green]')
400+
console.print(f"[green] Upload successful! \n {pretty_res} [/green]")
401+
399402

400403
@staging_cli.command("delete-dir")
401404
def cmd_delete_dir(
402405
slug: str = ...,
403-
file_name: str = Option(None, help="deletes a specified file within the slug directory.")
406+
file_name: str = Option(
407+
None, help="deletes a specified file within the slug directory."
408+
),
404409
):
405410
"""Delete all objects under SLUG/ in the staging bucket."""
406411
staging_delete_dir(slug, file_name)
407-
console.print(f"[green] Delete successful! \n Deleted objects under slug: {slug} [/green]")
412+
console.print(
413+
f"[green] Delete successful! \n Deleted objects under slug: {slug} [/green]"
414+
)
415+
408416

409417
@staging_cli.command("list")
410418
def cmd_list_dir(
411419
slug: str = ...,
412420
page_token: int = Option(0, "--page-token", "-t", help="Offset to start from"),
413421
page_size: int = Option(10, "--page-size", "-s", help="Items per page"),
414-
more: bool = Option(False, "--more", "-m", help="Interactively page through results"),
422+
more: bool = Option(
423+
False, "--more", "-m", help="Interactively page through results"
424+
),
415425
):
416426
"""List paginated files under SLUG."""
417427
if not more:
418428
page = staging_list_dir(slug, page_token=page_token, page_size=page_size)
419429
files = json.dumps(page, indent=2)
420-
console.print(f'[green] {files} [/green]')
430+
console.print(f"[green] {files} [/green]")
421431
return
422432

423433
token = page_token
424434
while True:
425435
page = staging_list_dir(slug, page_token=token, page_size=page_size)
426436
for f in page["files"]:
427-
console.print(f'[green]{f}[/green]')
437+
console.print(f"[green]{f}[/green]")
428438
if page["next_page_token"] is None:
429439
print("\n-- End of list --")
430440
break
431-
resp = input("\nPress Enter for next page, or type 'exit' to stop: ").strip().lower()
441+
resp = (
442+
input("\nPress Enter for next page, or type 'exit' to stop: ")
443+
.strip()
444+
.lower()
445+
)
432446
if resp in ("exit", "quit", "q"):
433447
break
434448
token = page["next_page_token"]

0 commit comments

Comments
 (0)