diff --git a/.gitignore b/.gitignore index 240ba16..17d1214 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ *.pyc *.xml .coverage -credentials.py .settings/* .project .pydvproject @@ -11,6 +10,5 @@ bak/* dist/* build/* sdata/* -sdata2/* test/sdata/* src/MpApi_M3.egg-info/* diff --git a/src/mpapi/chunky.py b/src/mpapi/chunky.py index 7f53d14..8da4f34 100644 --- a/src/mpapi/chunky.py +++ b/src/mpapi/chunky.py @@ -315,7 +315,7 @@ def _relatedItems( # binary_file.write(r.content) return etree.fromstring(r.content, ETparser) - def _savedQuery(self, *, Type: str = "Object", ID: int, offset: int = 0): + def _savedQuery(self, *, Type: str = "Object", ID: int, offset: int = 0) -> Module: return self.api.runSavedQuery2( Type=Type, ID=ID, offset=offset, limit=self.chunkSize ) diff --git a/src/mpapi/getAttachments.py b/src/mpapi/getAttachments.py index f62a3b6..080b9a1 100644 --- a/src/mpapi/getAttachments.py +++ b/src/mpapi/getAttachments.py @@ -83,23 +83,23 @@ def __init__( self.force = force # default for saving new request # if we're not using a cache - cache_fn = f"mul_{self.conf['type']}{self.conf['id']}.xml" + cache_fn = f"{self.conf['type']}{self.conf['id']}.xml" if cache: print("* loading cached response") - self.cache = Module(file=cache) + self.data = Module(file=cache) else: print("* launching new search") - m = self.get_multimedia_for_job() - m.toFile(path=cache_fn) - self.cache = m + self.data = self.get_multimedia_for_job() + self.data.toFile(path=cache_fn) if self.conf["attachments"]["name"] == "Cornelia": # in this mode we need object data... - self.cache += self._init_objData() - self.cache.toFile(path=cache) + self.data += self._init_objData() + if not cache: + self.data.toFile(path=cache_fn) - self.process_response(data=self.cache) + self.process_response(data=self.data) def process_response(self, *, data: Module) -> None: print("* processing response") @@ -248,7 +248,7 @@ def _get_single_attachment(self, *, item, ID: int, out_dir: Path) -> None: match self.conf["attachments"]["name"]: case "Cornelia": - res = self.cache.xpath(f""" + res = self.data.xpath(f""" /m:application/m:modules/m:module[ @name = 'Object' ]/m:moduleItem/m:moduleReference[ @@ -296,21 +296,17 @@ def _get_out_dir(self) -> Path: return out_dir def _init_objData(self) -> None: - obj_fn = Path(f"obj_{self.conf['type']}{self.conf['id']}.xml") - if self.cache: - if self.cache.actualSize(module="Object") > 0: + # obj_fn = Path(f"obj_{self.conf['type']}{self.conf['id']}.xml") + if self.data: + if self.data.actualSize(module="Object") > 0: return Module() - if self.cache.exists(): - objData = Module(file=str(self.cache)) - elif obj_fn.exists(): - objData = Module(file=obj_fn) else: print("getting objData from fresh query") if self.conf["type"] == "query": objData = self.api.runSavedQuery2(Type="query", ID=self.conf["id"]) else: objData = self._get_obj_group(grpId=self.conf["id"]) - objData.toFile(path=obj_fn) + # objData.toFile(path=obj_fn) return objData def _qm_type(self, *, query: Search, Id: int): diff --git a/src/mpapi/mink.py b/src/mpapi/mink.py index 772348c..1f74bc1 100644 --- a/src/mpapi/mink.py +++ b/src/mpapi/mink.py @@ -348,3 +348,23 @@ def _parse_conf(self, job: str, fn: Path) -> dict: except KeyError: raise SyntaxError("job '{job}' missing config value '{key}'") return job_data + + +if __name__ == "__main__": + # since fvh is blocked by Windows group policy + import argparse + from mpapi.constants import get_credentials + + user, pw, baseURL = get_credentials() + + 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.toml") + 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) + Mink(job=args.job, conf=args.conf, baseURL=baseURL, pw=pw, user=user)