Skip to content

Commit

Permalink
Load the old version in case the McM package is not installed
Browse files Browse the repository at this point in the history
This is intended for a smoother integration to avoid import errors with
the user's code. This is a temporary workaround that will be removed in the
future.

1. Re-use old function signatures accessing internal methods for the
   `McM` object.
2. Import the old version from AFS if required.
  • Loading branch information
ggonzr committed Aug 30, 2024
1 parent a944f5b commit 9bab77e
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions bin/utils/request_fragment_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/env python3
import os
import warnings
import sys
import re
import argparse
Expand Down Expand Up @@ -56,20 +57,34 @@
try:
from rest import McM
except ModuleNotFoundError as e:
import_msg = (
"Unable to import the McM module. "
"Install this module in your execution environment "
"by following the instructions available at: "
"https://github.com/cms-PdmV/mcm_scripts"
)
raise ModuleNotFoundError(import_msg) from e
old_version_afs = '/afs/cern.ch/cms/PPD/PdmV/tools/McM'
try:
# INFO: Temporarily load the old version to avoid crashes with non-updated user code.
sys.path.append(old_version_afs)
from rest import McM

version_msg = (
"An old version of the McM module has been loaded from: %s. "
"This is a temporal patch to avoid unforeseen import errors with user's code. "
"Install a recent version following the instructions available at "
"https://github.com/cms-PdmV/mcm_scripts for future executions."
) % (old_version_afs)
warnings.warn(version_msg, DeprecationWarning)

except ModuleNotFoundError as e:
import_msg = (
"Install this module in your execution environment "
"by following the instructions available at: "
"https://github.com/cms-PdmV/mcm_scripts"
)
raise ModuleNotFoundError(import_msg) from e

mcm = McM(id=None, dev=args.dev, debug=args.debug)
mcm_link = mcm.server

def get_request(prepid):
if args.local is False:
result = mcm._get('public/restapi/requests/get/%s' % (prepid))
result = mcm._McM__get('public/restapi/requests/get/%s' % (prepid))
if args.download_json is True:
with open("request_"+prepid+".json",'w') as f:
json.dump(result,f)
Expand All @@ -85,7 +100,7 @@ def get_request(prepid):
return result

def get_range_of_requests(query):
result = mcm._put('public/restapi/requests/listwithfile', data={'contents': query})
result = mcm._McM__put('public/restapi/requests/listwithfile', data={'contents': query})
if not result:
return {}

Expand All @@ -94,15 +109,15 @@ def get_range_of_requests(query):


def get_ticket(prepid):
result = mcm._get('public/restapi/mccms/get/%s' % (prepid))
result = mcm._McM__get('public/restapi/mccms/get/%s' % (prepid))
if not result:
return {}

result = result.get('results', {})
return result

def get_requests_from_datasetname(dn):
raw_result = mcm._get(
raw_result = mcm._McM__get(
"public/restapi/requests/from_dataset_name/%s" % (dn)
)
if not raw_result:
Expand Down

0 comments on commit 9bab77e

Please sign in to comment.