def __init__(self): token_store = InMemoryTokenStore() self.oncat = pyoncat.ONCat( 'https://oncat.ornl.gov', client_id=CLIENT_ID, client_secret=None, token_getter=token_store.get_token, token_setter=token_store.set_token, flow=pyoncat.RESOURCE_OWNER_CREDENTIALS_FLOW, ) self.username = getpass.getuser()
def _get_run_info(instrument, run_number, facility='SNS'): """ Get ONCat info for the specified run Notes: At the moment we do not catalog reduced data :param str instrument: instrument short name :param str run_number: run number :param str facility: facility name (SNS or HFIR) """ run_info = {} cached_entry = [] #CatalogCache.objects.filter(data_path="%s/%s" % (instrument, run_number)) if len(cached_entry) > 0: return dict(title=cached_entry[0].title, proposal=cached_entry[0].proposal) if not HAVE_ONCAT: return run_info try: oncat = pyoncat.ONCat( settings.CATALOG_URL, # Here we're using the machine-to-machine "Client Credentials" flow, # which requires a client ID and secret, but no *user* credentials. flow = pyoncat.CLIENT_CREDENTIALS_FLOW, client_id = settings.CATALOG_ID, client_secret = settings.CATALOG_SECRET, ) oncat.login() datafiles = oncat.Datafile.list( facility = facility, instrument = instrument.upper(), projection = ['experiment', 'location', 'metadata.entry.title'], tags = ['type/raw'], ranges_q = 'indexed.run_number:%s' % str(run_number) ) if datafiles: run_info['title'] = datafiles[0].metadata.get('entry', {}).get('title', None) run_info['proposal'] = datafiles[0].experiment run_info['location'] = datafiles[0].location except: logging.error("Communication with ONCat server failed: %s", sys.exc_value) return run_info
def ingest(file_path): # Use PyONCat v1.3.1 or above. assert tuple(map(int, pyoncat.__version__.split("."))) >= (1, 3, 1) # Use the testing instance of ONCat. ONCAT_URL = "https://oncat-testing.ornl.gov" # These credentials can be used for manual testing. The autoreducer VM's have # their own client credentials which should be used. CLIENT_ID = "b883cec7-d977-4015-8ecd-e6c3d9a33582" CLIENT_SECRET = "2977f72c-2b92-4540-a482-126b72eabb62" SCOPES = ["api:read", "api:write:location"] oncat = pyoncat.ONCat( ONCAT_URL, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, flow=pyoncat.CLIENT_CREDENTIALS_FLOW, scopes=SCOPES, ) oncat.Reduction.create({"location": file_path})
def is_valid_password(self): userid = str(self.ui.ucams.text()).strip() password = str(self.ui.password.text()) # Initialize token store token_store = InMemoryTokenStore() # # Setup ONcat object # oncat = pyoncat.ONCat( # 'https://oncat.ornl.gov', # client_id='cf46da72-9279-4466-bc59-329aea56bafe', # client_secret=None, # token_getter=token_store.get_token, # token_setter=token_store.set_token, # flow=pyoncat.RESOURCE_OWNER_CREDENTIALS_FLOW # ) # pyoncat is not available if pyoncat is None: return False # Setup ONcat object oncat = pyoncat.ONCat('https://oncat.ornl.gov', client_id='cf46da72-9279-4466-bc59-329aea56bafe', scopes=['api:read', 'settings:read'], client_secret=None, token_getter=token_store.get_token, token_setter=token_store.set_token, flow=pyoncat.RESOURCE_OWNER_CREDENTIALS_FLOW) try: oncat.login(userid, password) self.parent.ucams = userid self.parent.oncat = oncat except: return False return True
# Check binning is correct, if not re-reduce if ws.getRun().hasProperty(def_x): x = ws.getRun().getLogData(def_x).value if len(x) > 1: step_size = (x[-1]-x[0])/(len(x)-1) if not np.isclose(step_size, 0.05, atol=0.001): ws = HB2AReduce(filename, BinWidth=step_size, Scale=20000) SaveFocusedXYE(ws, Filename=os.path.join(outdir, output_file), SplitFiles=False, IncludeHeader=False) div = SavePlot1D(ws, OutputType='plotly') ################################################################################ # login to oncat oncat = pyoncat.ONCat( 'https://oncat.ornl.gov', client_id=client.ID, client_secret=client.SECRET, flow=pyoncat.CLIENT_CREDENTIALS_FLOW ) oncat.login() filename = sys.argv[1] ipts = filename.split('/')[3] ################################################################################ # create summary table datafile = oncat.Datafile.retrieve( filename, facility="HFIR", instrument="HB2A",
CLIENT_ID = '9e736eae-f90c-4513-89cf-53607eee5165' CLIENT_SECRET = None class InMemoryTokenStore(object): def __init__(self): self._token = None def set_token(self, token): self._token = token def get_token(self): return self._token token_store = InMemoryTokenStore() oncat = pyoncat.ONCat('https://oncat.ornl.gov', client_id=CLIENT_ID, client_secret=CLIENT_SECRET, token_getter=token_store.get_token, token_setter=token_store.set_token, flow=pyoncat.RESOURCE_OWNER_CREDENTIALS_FLOW) if token_store.get_token() is None: username = getpass.getuser() password = getpass.getpass() oncat.login(username, password) print(token_store.get_token()['access_token'])