Skip to content

Commit

Permalink
hack for mink.py to run it inspite of blocked group policy
Browse files Browse the repository at this point in the history
  • Loading branch information
mokko committed Jul 27, 2024
1 parent ddd4356 commit 88b5174
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.pyc
*.xml
.coverage
credentials.py
.settings/*
.project
.pydvproject
Expand All @@ -11,6 +10,5 @@ bak/*
dist/*
build/*
sdata/*
sdata2/*
test/sdata/*
src/MpApi_M3.egg-info/*
2 changes: 1 addition & 1 deletion src/mpapi/chunky.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
30 changes: 13 additions & 17 deletions src/mpapi/getAttachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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[
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions src/mpapi/mink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 88b5174

Please sign in to comment.