Commit 40530dff authored by Manuela Kuhn's avatar Manuela Kuhn

Cleanup of old/unnecessary files and directories + added comments

parent 83400fa1
......@@ -59,7 +59,7 @@ cp -a src/hidra_control/*.py %{buildroot}/opt/%{name}/src/hidra_control/
# conf
mkdir -p %{buildroot}/opt/%{name}/conf
cp conf/datamanager.conf conf/datareceiver.conf conf/nexusReceiver.conf %{buildroot}/opt/%{name}/conf/
cp conf/datamanager.conf conf/datareceiver.conf %{buildroot}/opt/%{name}/conf/
# systemd unit files
mkdir -p %{buildroot}/%{_unitdir}
......
......@@ -643,7 +643,7 @@ class Transfer():
option [<protocol>, <ip>, <port>]
"""
if option == "status_check":
# TODO create Thread shich handles this asynchroniously
# TODO create Thread which handles this asynchroniously
if self.status_check_socket is not None:
self.log.error("Status check is already enabled (used port: "
"{0})".format(self.status_check_port))
......
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
try:
# search in global python modules first
import hidra
except:
# then search in local modules
BASE_PATH = os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.realpath(__file__))))
API_PATH = os.path.join(BASE_PATH, "src", "APIs")
if API_PATH not in sys.path:
sys.path.append(API_PATH)
del API_PATH
import hidra
def do_set(obj):
det = "lsdma-lab04"
# check if beamline is allowed to get data from this detector
hidra.check_netgroup(det,
"p00",
log=hidra.control.LoggingFunction())
obj.set("local_target", "local")
obj.set("det_ip", det)
obj.set("det_api_version", "1.5.0")
obj.set("history_size", 2000)
obj.set("store_data", False)
obj.set("remove_data", False)
obj.set("whitelist", "localhost")
def do_start(obj):
print ("Starting HiDRA (detector mode):", obj.do("start"))
def do_stop(obj):
print ("Stopping HiDRA (detector mode):", obj.do("stop"))
def do_status(obj):
print ("Status of HiDRA (detector mode):", obj.do("status"))
def do_getsettings(obj):
if obj.do("status") == "RUNNING":
print ("Configured settings:")
print ("Data is written to: {0}"
.format(obj.get("local_target")))
# print ("Detector IP: {0}"
# .format(obj.get("det_ip")))
# print ("Detector API version: {0}"
# .format(obj.get("det_api_version")))
# print ("History size: {0}"
# .format(obj.get("history_size")))
# print ("Store data: {0}"
# .format(obj.get("store_data")))
# print ("Remove data from the detector: {0}"
# .format(obj.get("remove_data")))
# print ("Whitelist: {0}"
# .format(obj.get("whitelist")))
else:
print ("HiDRA is not running")
if __name__ == '__main__':
obj = hidra.Control("p00", use_log=None)
try:
do_getsettings(obj)
do_set(obj)
do_start(obj)
do_getsettings(obj)
print ()
new_target = "current/raw"
print ("Setting local_target to {0}".format(new_target))
obj.set("local_target", new_target)
do_getsettings(obj)
print ()
obj.stop()
obj = hidra.Control("p00", use_log=None)
do_getsettings(obj)
print ()
do_stop(obj)
finally:
obj.stop()
This diff is collapsed.
......@@ -101,7 +101,7 @@ def argument_parsing():
return params
def excecute_ldapsearch_(netgroup):
def excecute_ldapsearch_test(netgroup):
global whitelist
import zmq
......@@ -143,7 +143,7 @@ class CheckNetgroup (threading.Thread):
global changed_netgroup
while self.run_loop:
# new_whitelist = excecute_ldapsearch_(self.netgroup)
# new_whitelist = excecute_ldapsearch_test(self.netgroup)
new_whitelist = helpers.excecute_ldapsearch(self.netgroup)
# new elements added to whitelist
......
......@@ -307,7 +307,7 @@ class DataManager():
self.current_pid = os.getpid()
self.reestablish_time = 600
self.reestablish_time = 600 # in sec
try:
self.params = argument_parsing()
......
Current authors:
Forest Bond <forest@forestbond.com>
Henry Stern <henry@stern.ca>
inotifyx is a derived work, based on the following:
python-inotify by Manuel Amador <rudd-o@rudd-o.com>
inotify-glue.c from Beagle <http://beagle-project.org>
Copyright (c) 2004 Novell, Inc.
Copyright (c) 2005 Manuel Amador
Copyright (c) 2009-2014 Forest Bond
Copyright (c) 2014 Henry Stern
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
======================
inotifyx Release Notes
======================
.. contents::
inotifyx 0.2.2 2014-08-25
=========================
* Added release file to MANIFEST.in. This fixes incorrect version number
reporting for release tarballs.
(Forest Bond)
inotifyx 0.2.1 2014-08-25
=========================
* Some reference counting bugs in get_events were fixed. This prevents leaking
memory while processing events.
(Henry Stern)
* A bug with memory allocation failure handling in get_events was fixed. This
prevents a segmentation fault under low memory conditions.
(Forest Bond)
* inotify events with zero-length name fields are now properly handled.
Previously, segmentation faults and other errors would have occurred if such
events were received.
(Forest Bond)
* A distutils manifest is now provided. Source code tarballs can now be
generated via setup.py, and this mechanism will be used to generate official
release tarballs.
(Forest Bond)
* The "download_url" distutils option is no longer specified. Release tarballs
will be available directly from PyPI. This is now required by pip.
(Forest Bond)
inotifyx 0.2.0 2011-07-09
=========================
* The distutils option "download_url" is now specified. This should fix
problems using pip, zc.buildout, and other tools that rely on PyPI for
package downloads to install inotifyx. Thanks to Dariusz Suchojad for
the report.
(Forest Bond)
* inotifyx is now distributed as a Python package instead of a few bare
modules. The "_inotifyx" C extension is now shipped as "inotifyx.binding".
This change should be backwards compatible with respect to imports since
the C extension did not directly implement public interfaces.
(Forest Bond)
* A __version__ attribute is now provided. This specifies the version
of the inotifyx library. Thanks to Jérôme Laheurte for the suggestion.
(Forest Bond)
inotifyx 0.1.2 2011-03-31
=========================
* Threads are now allowed during I/O operations. Thanks to Jean-Baptiste
Denis for the report and patch.
(Forest Bond)
inotifyx 0.1.1 2009-10-18
=========================
* Fix integer truncation of timeout argument in get_events. Thanks to Eric
Firing for the report and patch.
(Forest Bond)
inotifyx 0.1.0 2009-04-26
=========================
* Initial release.
(Forest Bond)
Metadata-Version: 1.0
Name: inotifyx
Version: 0.2.2
Summary: Simple Linux inotify bindings
Home-page: https://launchpad.net/inotifyx/
Author: Forest Bond
Author-email: forest@forestbond.com
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
inotifyx is a simple Python binding to the Linux inotify file system event
monitoring API.
Documentation is provided in the module. To get help, start an interactive
Python session and type:
>>> import inotifyx
>>> help(inotifyx)
You can also test out inotifyx easily. The following command will print events
for /tmp:
python -m inotifyx /tmp
Tests can be run via setup.py:
./setup.py test
Note that the module must be built and installed for tests to run correctly.
In the future, this requirement will be lifted.
# Copyright (c) 2005 Manuel Amador
# Copyright (c) 2009-2011 Forest Bond
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
'''
inotifyx is a simple Python binding to the Linux inotify file system event
monitoring API.
Generally, usage is as follows:
>>> fd = init()
>>> try:
... wd = add_watch(fd, '/path', IN_ALL_EVENTS)
... events = get_events(fd)
... rm_watch(fd, wd)
... finally:
... os.close(fd)
'''
import os, select
from inotifyx import binding
from inotifyx.distinfo import version as __version__
constants = {}
for name in dir(binding):
if name.startswith('IN_'):
globals()[name] = constants[name] = getattr(binding, name)
init = binding.init
rm_watch = binding.rm_watch
add_watch = binding.add_watch
class InotifyEvent(object):
'''
InotifyEvent(wd, mask, cookie, name)
A representation of the inotify_event structure. See the inotify
documentation for a description of these fields.
'''
wd = None
mask = None
cookie = None
name = None
def __init__(self, wd, mask, cookie, name):
self.wd = wd
self.mask = mask
self.cookie = cookie
self.name = name
def __str__(self):
return '%s: %s' % (self.wd, self.get_mask_description())
def __repr__(self):
return '%s(%s, %s, %s, %s)' % (
self.__class__.__name__,
repr(self.wd),
repr(self.mask),
repr(self.cookie),
repr(self.name),
)
def get_mask_description(self):
'''
Return an ASCII string describing the mask field in terms of
bitwise-or'd IN_* constants, or 0. The result is valid Python code
that could be eval'd to get the value of the mask field. In other
words, for a given event:
>>> from inotifyx import *
>>> assert (event.mask == eval(event.get_mask_description()))
'''
parts = []
for name, value in constants.items():
if self.mask & value:
parts.append(name)
if parts:
return '|'.join(parts)
return '0'
def get_events(fd, *args):
'''
get_events(fd[, timeout])
Return a list of InotifyEvent instances representing events read from
inotify. If timeout is None, this will block forever until at least one
event can be read. Otherwise, timeout should be an integer or float
specifying a timeout in seconds. If get_events times out waiting for
events, an empty list will be returned. If timeout is zero, get_events
will not block.
'''
return [
InotifyEvent(wd, mask, cookie, name)
for wd, mask, cookie, name in binding.get_events(fd, *args)
]
if __name__ == '__main__':
import sys
if len(sys.argv) == 1:
print >>sys.stderr, 'usage: inotify path [path ...]'
sys.exit(1)
paths = sys.argv[1:]
fd = init()
wd_to_path = {}
try:
for path in paths:
wd = add_watch(fd, path)
wd_to_path[wd] = path
try:
while True:
events = get_events(fd)
for event in events:
path = wd_to_path[event.wd]
parts = [event.get_mask_description()]
if event.name:
parts.append(event.name)
print '%s: %s' % (path, ' '.join(parts))
except KeyboardInterrupt:
pass
finally:
os.close(fd)
/*
* Copyright (c) 2004 Novell, Inc.
* Copyright (c) 2005 Manuel Amador
* Copyright (c) 2009-2014 Forest Bond
* Copyright (c) 2014 Henry Stern
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <Python.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/inotify.h>
#include <linux/types.h>
#include <linux/limits.h>
#define MAX_PENDING_PAUSE_COUNT 5
#define PENDING_PAUSE_MICROSECONDS 2000
#define PENDING_THRESHOLD(qsize) ((qsize) >> 1)
#define EVENT_SIZE (sizeof (struct inotify_event))
#define BUF_LEN (1024 * (EVENT_SIZE + 16))
static PyObject * inotifyx_init(PyObject *self, PyObject *args) {
int fd;
Py_BEGIN_ALLOW_THREADS;
fd = inotify_init();
Py_END_ALLOW_THREADS;
if(fd < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
return Py_BuildValue("i", fd);
}
static PyObject * inotifyx_add_watch(PyObject *self, PyObject *args) {
int fd;
char *path;
int watch_descriptor;
uint32_t mask;
mask = IN_ALL_EVENTS;
if(! PyArg_ParseTuple(args, "is|i", &fd, &path, &mask)) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS;
watch_descriptor = inotify_add_watch(fd, (const char *)path, mask);
Py_END_ALLOW_THREADS;
if(watch_descriptor < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
return Py_BuildValue("i", watch_descriptor);
}
static PyObject * inotifyx_rm_watch(PyObject *self, PyObject *args) {
int fd;
int watch_descriptor;
int retvalue;
if(! PyArg_ParseTuple(args, "ii", &fd, &watch_descriptor)) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS;
retvalue = inotify_rm_watch(fd, watch_descriptor);
Py_END_ALLOW_THREADS;
if(retvalue < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
return Py_BuildValue("i", retvalue);
}
static PyObject * inotifyx_get_events(PyObject *self, PyObject *args) {
int fd;
static char buf[BUF_LEN];
int i;
int len;
float timeout_arg;
struct timeval timeout;
void *ptimeout;
struct inotify_event *event;
fd_set read_fds;
int select_retval;
timeout_arg = -1.0;
if(! PyArg_ParseTuple(args, "i|f", &fd, &timeout_arg)) {
return NULL;
}
if(timeout_arg < 0.0) {
ptimeout = NULL;
} else {
timeout.tv_sec = (int)timeout_arg;
timeout.tv_usec = (int)(1000000.0 * (timeout_arg - (float)((int) timeout_arg)));
ptimeout = &timeout;
}
FD_ZERO(&read_fds);
FD_SET(fd, &read_fds);
Py_BEGIN_ALLOW_THREADS;
select_retval = select(fd + 1, &read_fds, NULL, NULL, ptimeout);
Py_END_ALLOW_THREADS;
if(select_retval == 0) {
// Timed out.
return PyList_New(0);
} else if(select_retval < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
PyObject* retvalue = PyList_New(0);
if (retvalue == NULL)
return NULL;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
ptimeout = &timeout;
while (1) {
Py_BEGIN_ALLOW_THREADS;
len = read(fd, buf, BUF_LEN);
Py_END_ALLOW_THREADS;
if(len < 0) {
PyErr_SetFromErrno(PyExc_IOError);
Py_DECREF(retvalue);
return NULL;
} else if(len == 0) {
PyErr_SetString(PyExc_IOError, "event buffer too small");
Py_DECREF(retvalue);
return NULL;
}
i = 0;
while(i < len) {
event = (struct inotify_event *)(& buf[i]);
PyObject* value = NULL;
if(event->len > 0 && event->name[0] != '\0') {
value = Py_BuildValue(
"iiis",
event->wd,
event->mask,
event->cookie,
event->name
);
} else {
value = Py_BuildValue(
"iiiO",
event->wd,
event->mask,
event->cookie,
Py_None
);
}
if(PyList_Append(retvalue, value) == -1) {
Py_DECREF(retvalue);
Py_DECREF(value);
return NULL;
}
Py_DECREF(value);
i += EVENT_SIZE + event->len;
}
FD_ZERO(&read_fds);
FD_SET(fd, &read_fds);
Py_BEGIN_ALLOW_THREADS;
select_retval = select(fd + 1, &read_fds, NULL, NULL, ptimeout);
Py_END_ALLOW_THREADS;
if (select_retval <= 0)
break;
}
return retvalue;
}
static PyMethodDef InotifyMethods[] = {
{
"init",
inotifyx_init,
METH_VARARGS,
(
"init()\n\n"
"Initialize an inotify instance and return the associated file\n"
"descriptor. The file descriptor should be closed via os.close\n"
"after it is no longer needed."
)
},
{
"add_watch",
inotifyx_add_watch,
METH_VARARGS,
(
"add_watch(fd, path[, mask])\n\n"
"Add a watch for path and return the watch descriptor.\n"
"fd should be the file descriptor returned by init.\n"
"If left unspecified, mask defaults to IN_ALL_EVENTS.\n"
"See the inotify documentation for details."
)
},
{
"rm_watch",
inotifyx_rm_watch,
METH_VARARGS,
(
"rm_watch(fd, wd)\n\n"
"Remove the watch associated with watch descriptor wd.\n"
"fd should be the file descriptor returned by init.\n"