本文整理汇总了Python中server_common.utilities.print_and_log函数的典型用法代码示例。如果您正苦于以下问题:Python print_and_log函数的具体用法?Python print_and_log怎么用?Python print_and_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_and_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_command
def execute_command(self, command, is_query):
"""Executes a command on the database, and returns all values
Args:
command (string): the SQL command to run
is_query (boolean): is this a query (i.e. do we expect return values)
Returns:
values (list): list of all rows returned. None if not is_query
"""
conn = None
curs = None
values = None
try:
conn = self._get_connection()
curs = conn.cursor()
curs.execute(command)
if is_query:
values = curs.fetchall()
# Commit as part of the query or results won't be updated between subsequent transactions. Can lead
# to values not auto-updating in the GUI.
conn.commit()
except Exception as err:
print_and_log("Error executing command on database: %s" % err.message, "MAJOR")
finally:
if curs is not None:
curs.close()
if conn is not None:
conn.close()
return values
示例2: get_active_pvs
def get_active_pvs(self):
"""Queries the database for active PVs.
Returns:
list : A list of the PVs in running IOCs
"""
values = []
sqlquery = "SELECT pvinfo.pvname, pvs.record_type, pvs.record_desc, pvs.iocname FROM pvinfo"
sqlquery += " INNER JOIN pvs ON pvs.pvname = pvinfo.pvname"
# Ensure that only active IOCs are considered
sqlquery += " WHERE (pvs.iocname in (SELECT iocname FROM iocrt WHERE running=1) AND infoname='INTEREST')"
try:
# Get as a plain list of lists
values = [list(element) for element in self._db.query(sqlquery)]
# Convert any bytearrays
for i, pv in enumerate(values):
for j, element in enumerate(pv):
if type(element) == bytearray:
values[i][j] = element.decode("utf-8")
except Exception as err:
print_and_log("issue with getting active PVs: %s" % err, "MAJOR", "DBSVR")
return values
示例3: update_iocs_status
def update_iocs_status(self):
"""Accesses the db to get a list of IOCs and checks to see if they are currently running
Returns:
list : The names of running IOCs
"""
with self._running_iocs_lock:
self._running_iocs = list()
try:
# Get all the iocnames and whether they are running, but ignore IOCs associated with PSCTRL
sqlquery = "SELECT iocname, running FROM iocrt WHERE (iocname NOT LIKE 'PSCTRL_%')"
rows = self._db.query(sqlquery)
for row in rows:
# Check to see if running using CA and procserv
try:
if self._procserve.get_ioc_status(self._prefix, row[0]).upper() == "RUNNING":
self._running_iocs.append(row[0])
if row[1] == 0:
# This should only get called if the IOC failed to tell the DB it started
self._db.update("UPDATE iocrt SET running=1 WHERE iocname='%s'" % row[0])
else:
if row[1] == 1:
self._db.update("UPDATE iocrt SET running=0 WHERE iocname='%s'" % row[0])
except Exception as err:
# Fail but continue - probably couldn't find procserv for the ioc
print_and_log("issue with updating IOC status: %s" % err, "MAJOR", "DBSVR")
except Exception as err:
print_and_log("issue with updating IOC statuses: %s" % err, "MAJOR", "DBSVR")
return self._running_iocs
示例4: _get_iocs
def _get_iocs(self, include_running=False):
# Get IOCs from DatabaseServer
try:
return self._db_client.get_iocs()
except Exception as err:
print_and_log("Could not retrieve IOC list: %s" % str(err), "MAJOR")
return []
示例5: _start_config_iocs
def _start_config_iocs(self):
# Start the IOCs, if they are available and if they are flagged for autostart
# Note: autostart means the IOC is started when the config is loaded,
# restart means the IOC should automatically restart if it stops for some reason (e.g. it crashes)
for n, ioc in self._active_configserver.get_all_ioc_details().iteritems():
try:
# IOCs are restarted if and only if auto start is True. Note that auto restart instructs proc serv to
# restart an IOC if it terminates unexpectedly and does not apply here.
if ioc.autostart:
# Throws if IOC does not exist
running = self._ioc_control.get_ioc_status(n)
if running == "RUNNING":
# Restart it
self._ioc_control.restart_ioc(n)
else:
# Start it
self._ioc_control.start_ioc(n)
except Exception as err:
print_and_log("Could not (re)start IOC %s: %s" % (n, str(err)), "MAJOR")
# Give it time to start as IOC has to be running to be able to set restart property
sleep(2)
for n, ioc in self._active_configserver.get_all_ioc_details().iteritems():
if ioc.autostart:
# Set the restart property
print_and_log("Setting IOC %s's auto-restart to %s" % (n, ioc.restart))
self._ioc_control.set_autorestart(n, ioc.restart)
示例6: consume_write_queue
def consume_write_queue(self):
"""Actions any requests on the write queue.
Queue items are tuples with three values:
the method to call; the argument(s) to send (tuple); and, the description of the state (string))
For example:
self.load_config, ("configname",), "LOADING_CONFIG")
"""
while True:
while len(self.write_queue) > 0:
if self._filewatcher is not None: self._filewatcher.pause()
with self.write_lock:
cmd, arg, state = self.write_queue.pop(0)
self.update_server_status(state)
try:
if arg is not None:
cmd(*arg)
else:
cmd()
except Exception as err:
print_and_log(
"Error executing write queue command %s for state %s: %s" % (cmd.__name__, state, err.message),
"MAJOR")
self.update_server_status("")
if self._filewatcher is not None: self._filewatcher.resume()
sleep(1)
示例7: _pull
def _pull(self):
try:
self.remote.pull()
except GitCommandError as e:
# Most likely server issue
print_and_log("Unable to pull configurations from remote repo", "MINOR")
raise GitPullFailed()
示例8: _set_rc_values
def _set_rc_values(self, bn, settings):
for key, value in settings.iteritems():
if key.upper() in TAG_RC_DICT.keys():
try:
self._channel_access.caput(self._block_prefix + bn + TAG_RC_DICT[key.upper()], value)
except Exception as err:
print_and_log("Problem with setting runcontrol for %s: %s" % (bn, err))
示例9: _clear_autosave_files
def _clear_autosave_files(self):
for fname in os.listdir(self._autosave_dir):
file_path = os.path.join(self._autosave_dir, fname)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as err:
print_and_log("Problem deleting autosave files for the run-control IOC: %s" % str(err), "MAJOR")
示例10: delete_pv_from_db
def delete_pv_from_db(self, name):
if name in manager.pvs[self.port]:
print_and_log("Removing PV %s" % name)
fullname = manager.pvs[self.port][name].name
del manager.pvs[self.port][name]
del manager.pvf[fullname]
del self.pvDB[name]
del PVDB[name]
示例11: _upload_archive_config
def _upload_archive_config(self):
f = os.path.abspath(self._uploader_path)
if os.path.isfile(f):
print_and_log("Running archiver settings uploader: %s" % f)
p = Popen(f)
p.wait()
else:
print_and_log("Could not find specified archiver uploader batch file: %s" % self._uploader_path)
示例12: reload_current_config
def reload_current_config(self):
""" Reload the current configuration."""
current_config_name = self.get_config_name()
if current_config_name == "":
print_and_log("No current configuration defined. Nothing to reload.")
return
print_and_log("Trying to reload current configuration %s" % current_config_name)
self.load_active(current_config_name)
示例13: restart_ioc
def restart_ioc(self, prefix, ioc):
"""Restarts the specified IOC.
Args:
prefix (string): The prefix for the instrument
ioc (string): The name of the IOC
"""
print_and_log("Restarting IOC %s" % ioc)
ChannelAccess.caput(self.generate_prefix(prefix, ioc) + ":RESTART", 1)
示例14: start_ioc
def start_ioc(self, prefix, ioc):
"""Starts the specified IOC
Args:
prefix (string): The prefix of the instrument the IOC is being run on
ioc (string): The name of the IOC to start
"""
print_and_log("Starting IOC %s" % ioc)
ChannelAccess.caput(self.generate_prefix(prefix, ioc) + ":START", 1)
示例15: reload_current_config
def reload_current_config(self):
"""Reload the current configuration."""
try:
print_and_log("Reloading current configuration")
self._active_configserver.reload_current_config()
# If we get this far then assume the config is okay
self._initialise_config(full_init=True)
except Exception as err:
print_and_log(str(err), "MAJOR")