diff --git a/siriuspy/siriuspy/clientarch/client.py b/siriuspy/siriuspy/clientarch/client.py index 189ccd61f..fa6c4f0d2 100644 --- a/siriuspy/siriuspy/clientarch/client.py +++ b/siriuspy/siriuspy/clientarch/client.py @@ -1,7 +1,9 @@ -#!/usr/bin/env python-sirius """Fetcher module. -See https://slacmshankar.github.io/epicsarchiver_docs/userguide.html +See + https://slacmshankar.github.io/epicsarchiver_docs/userguide.html + http://slacmshankar.github.io/epicsarchiver_docs/details.html + http://slacmshankar.github.io/epicsarchiver_docs/api/mgmt_scriptables.html """ from threading import Thread as _Thread @@ -16,6 +18,7 @@ from .. import envars as _envars from . import exceptions as _exceptions +from .time import Time as _Time class ClientArchiver: @@ -134,6 +137,27 @@ def getPausedPVsReport(self): resp = self._make_request(url, return_json=True) return None if not resp else resp + def getRecentlyModifiedPVs(self, limit=None, epoch_time=True): + """Get list of PVs with recently modified PVTypeInfo. + + Currently version of the epics archiver appliance returns pvname + list from oldest to newest modified timestamps.""" + method = 'getRecentlyModifiedPVs' + # get data + if limit is not None: + method += f'?limit={str(limit)}' + url = self._create_url(method=method) + resp = self._make_request(url, return_json=True) + + # convert to epoch, if the case + if resp and epoch_time: + for item in resp: + modtime = item['modificationTime'][:-7] # remove ISO8601 offset + epoch_time = _Time.conv_to_epoch(modtime, '%b/%d/%Y %H:%M:%S') + item['modificationTime'] = epoch_time + + return None if not resp else resp + def pausePVs(self, pvnames): """Pause PVs.""" if not isinstance(pvnames, (list, tuple)): diff --git a/siriuspy/siriuspy/clientarch/pvarch.py b/siriuspy/siriuspy/clientarch/pvarch.py index d481d552a..ad0d81a22 100644 --- a/siriuspy/siriuspy/clientarch/pvarch.py +++ b/siriuspy/siriuspy/clientarch/pvarch.py @@ -112,9 +112,11 @@ def is_archived(self): return False return True - def update(self): + def update(self, timeout=None): """.""" self.connect() + if timeout is not None: + self.timeout = timeout data = self.connector.getPVDetails(self.pvname) if not data: return False @@ -280,9 +282,11 @@ def severity(self): """Severity data.""" return self._severity - def update(self, mean_sec=None, parallel=True): + def update(self, mean_sec=None, parallel=True, timeout=None): """Update.""" self.connect() + if timeout is not None: + self.timeout = timeout if None in (self.timestamp_start, self.timestamp_stop): print('Start and stop timestamps not defined! Aborting.') return @@ -493,9 +497,11 @@ def parallel_query_bin_interval(self, new_intvl): self._pvdata[pvname].parallel_query_bin_interval = \ self._parallel_query_bin_interval - def update(self, mean_sec=None, parallel=True): + def update(self, mean_sec=None, parallel=True, timeout=None): """Update.""" self.connect() + if timeout is not None: + self.timeout = None if None in (self.timestamp_start, self.timestamp_stop): print('Start and stop timestamps not defined! Aborting.') return diff --git a/siriuspy/siriuspy/clientarch/time.py b/siriuspy/siriuspy/clientarch/time.py index 899573812..9983cd1e5 100644 --- a/siriuspy/siriuspy/clientarch/time.py +++ b/siriuspy/siriuspy/clientarch/time.py @@ -2,6 +2,7 @@ from . import exceptions as _exceptions from datetime import datetime as _datetime, timedelta as _timedelta +from calendar import timegm as _timegm class Time(_datetime): @@ -94,6 +95,13 @@ def __sub__(self, other): sub = super().__sub__(other) return Time(timestamp=sub.timestamp()) + @staticmethod + def conv_to_epoch(time, datetime_format): + """get epoch from datetime.""" + utc_time = _datetime.strptime(time, datetime_format) + epoch_time = _timegm(utc_time.timetuple()) + return epoch_time + def get_time_intervals( time_start, time_stop, interval, return_isoformat=False):