55os .environ ["USE_PYGEOS" ] = "0"
66
77import re
8+ from pathlib import Path
89from sys import stdin
910
1011from psycopg2 .sql import Identifier
12+ from rich .console import Console
1113from typer import Option
1214
1315from macrostrat .core import app
1719from macrostrat .map_integration .process .geometry import create_rgeom , create_webgeom
1820from macrostrat .map_integration .utils .file_discovery import find_gis_files
1921from macrostrat .map_integration .utils .map_info import get_map_info
22+ from macrostrat .map_integration .utils .staging_upload_dir import *
2023
2124from . import pipeline
2225from .commands .copy_sources import copy_macrostrat_sources
2831from .commands .sources import map_sources
2932from .database import get_database
3033from .migrations import run_migrations
34+ from .pipeline import upload_file
3135from .process import cli as _process
3236from .process .insert import _delete_map_data
3337from .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
4139help_text = f"""Ingest maps into Macrostrat.
4240
4341Active map: [bold cyan]{ app .state .get ("active_map" )} [/]
4442"""
45- console = Console ()
43+ console = Console ()
4644cli = IngestionCLI (no_args_is_help = True , name = "map-ingestion" , help = help_text )
4745
46+
4847@cli .command (name = "set-active" )
4948def 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):
256255staging_cli = IngestionCLI (no_args_is_help = True , help = "Staging pipeline & storage" )
257256cli .add_typer (staging_cli , name = "staging" )
258257
258+
259259def staging (
260260 slug : str ,
261261 data_path : str ,
@@ -382,11 +382,13 @@ def staging(
382382 f"\n Finished staging setup for { slug } . View map here: https://dev.macrostrat.org/maps/ingestion/{ source_id } / \n "
383383 )
384384
385+
385386staging_cli .add_command (staging , name = "ingest" )
386387
387- #------------------------------------------
388+ # ------------------------------------------
388389# commands nested under 'macrostrat maps staging...'
389390
391+
390392@staging_cli .command ("upload-dir" )
391393def 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" )
401404def 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" )
410418def 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 ("\n Press Enter for next page, or type 'exit' to stop: " ).strip ().lower ()
441+ resp = (
442+ input ("\n Press 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