Skip to content

Commit

Permalink
cleaning __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
mokko committed Oct 13, 2023
1 parent f559539 commit ca8761f
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions src/mpapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""An Unofficial Open Source Client for the MuseumPlus API"""

__version__ = "0.1.8" # cleanup, Vocabulary, validate cli
__version__ = "0.1.9" # replace pyexiv, cleanup __init__
import argparse
from getAttachments import GetAttachments
from mpapi.mink import Mink
Expand All @@ -9,8 +9,23 @@
from mpapi.constants import get_credentials
from mpapi.validate import Validate
from pathlib import Path
import sys

user, pw, baseURL = get_credentials()

def _login() -> MpApi:
user, pw, baseURL = get_credentials()
c = MpApi(baseURL=baseURL, pw=pw, user=user)


def _setup_args(parser):
parser.add_argument(
"-v", "--version", help="Display version information", action="store_true"
)
args = parser.parse_args()
if args.version:
print(f"Version: {__version__}")
sys.exit(0)
return args


def getDefinition():
Expand All @@ -21,14 +36,9 @@ def getDefinition():
help="module type (Object, Multimedia etc.); optional",
default=None,
)
parser.add_argument("-v", "--version", help="Display version information")
args = parser.parse_args()
args = _setup_args(parser)
c = _login()

if args.version:
print(f"Version: {__version__}")
sys.exit(0)

c = MpApi(baseURL=baseURL, pw=pw, user=user)
print(f"Logging in as '{user}'")
m = c.getDefinition2(mtype=args.mtype)
if args.mtype is None:
Expand All @@ -50,15 +60,9 @@ def getItem():
"-u", "--upload", help="Save in upload form", action="store_true"
)
parser.add_argument("-i", "--ID", help="ID")
parser.add_argument("-v", "--version", help="Display version information")
args = parser.parse_args()

if args.version:
print(f"Version: {__version__}")
sys.exit(0)
args = _setup_args(parser)

c = MpApi(baseURL=baseURL, pw=pw, user=user)
print(f"Logging in as '{user}'")
c = _login()
m = c.getItem2(mtype=args.mtype, ID=args.ID)
if args.upload:
fn = f"getItem-{args.mtype}{args.ID}u.xml"
Expand All @@ -79,19 +83,17 @@ def getAttachments():
parser.add_argument(
"-j", "--job", required=True, help="pick a job from getAttachments.jobs file"
)
args = parser.parse_args()
args = _setup_args(parser)

GetAttachments(baseURL=baseURL, job=args.job, user=user, pw=pw)


def mink():
parser = argparse.ArgumentParser(description="Commandline frontend for MpApi.py")
parser.add_argument("-j", "--job", help="job to run") # , required=True
parser.add_argument("-c", "--conf", help="config file", default="jobs.dsl")
parser.add_argument("-v", "--version", help="Display version information")
args = parser.parse_args()
if args.version:
print(f"Version: {__version__}")
sys.exit(0)
args = _setup_args(parser)

m = Mink(job=args.job, conf=args.conf, baseURL=baseURL, pw=pw, user=user)


Expand All @@ -100,24 +102,18 @@ def updateItem():
parser.add_argument("-f", "--file", help="File location to upload")
parser.add_argument("-i", "--id", help="moduleItem/@id")
parser.add_argument("-t", "--mtype", help="module type")
parser.add_argument("-v", "--version", help="Display version information")
args = parser.parse_args()
args = _setup_args(parser)

# todowe could extract module type and id from the record

required_args = ["file", "id", "mtype"]

if args.version:
print(f"Version: {__version__}")
sys.exit(0)

for req in required_args:
if not req in args:
raise SyntaxError("Required args not provided")

args = parser.parse_args()
m = Module(file=args.file)
c = MpApi(baseURL=baseURL, pw=pw, user=user)
c = _login()
m = c.uploadItem2(mtype=args.mtype, ID=args.ID)


Expand All @@ -126,12 +122,8 @@ def validate():
parser.add_argument(
"-m", "--mode", help="mode (module, search or vocabulary)", default="module"
)
parser.add_argument("-v", "--version", help="Display version information")
parser.add_argument("file", nargs="?")
args = parser.parse_args()
if args.version:
print(f"Version: {__version__}")
sys.exit(0)
args = _setup_args(parser)
if args.file is None:
raise SyntaxError("ERROR: Required arg 'file' not provided!")

Expand Down

0 comments on commit ca8761f

Please sign in to comment.