def find_plugins(): """ return (list of str): list of the filenames of the plugins available """ hf = get_home_folder() # Order of paths matters, so that the user can override a system plugin if os.name == "nt": paths = (os.path.join(odemis.__path__[0], u"plugins/"), # There is no official place for putting per-user system # overriding file, so just put with the config file. os.path.join(hf, u".config/odemis/plugins/") ) else: # hopefully this is Linux paths = (u"/usr/share/odemis/plugins/", u"/usr/share/local/odemis/plugins/", os.path.join(hf, u".local/share/odemis/plugins/"), ) plugins = {} # script name -> full path for p in paths: for fn in glob.glob(p + u"*.py"): if os.path.isfile(fn): # Discard previous plugin with same name sn = os.path.basename(fn) plugins[sn] = fn return sorted(plugins.values())
def find_plugins(): """ return (list of str): list of the filenames of the plugins available """ hf = get_home_folder() # Order of paths matters, so that the user can override a system plugin if os.name == "nt": # Typically, on Windows, the odemis package is a single file located into # a dedicated OdemisViewer folder which contains also all the dependencies # => search inside this folder paths = ( os.path.join(odemis.__path__[0], u"..", u"plugins"), # There is no official place for putting per-user system # overriding file, so just put with the config file. os.path.join(hf, u".config", u"odemis", u"plugins")) else: # hopefully this is Linux paths = ( u"/usr/lib/odemis/plugins", u"/usr/local/lib/odemis/plugins", os.path.join(hf, u".local/share/odemis/plugins"), ) plugins = {} # script name -> full path for p in paths: for fn in glob.glob(os.path.join(p, u"*.py")): if os.path.isfile(fn): # Discard previous plugin with same name sn = os.path.basename(fn) plugins[sn] = fn return sorted(plugins.values())
def find_plugins(): """ return (list of str): list of the filenames of the plugins available """ hf = get_home_folder() # Order of paths matters, so that the user can override a system plugin if os.name == "nt": paths = ( os.path.join(odemis.__path__[0], u"plugins/"), # There is no official place for putting per-user system # overriding file, so just put with the config file. os.path.join(hf, u".config/odemis/plugins/")) else: # hopefully this is Linux paths = ( u"/usr/share/odemis/plugins/", u"/usr/share/local/odemis/plugins/", os.path.join(hf, u".local/share/odemis/plugins/"), ) plugins = {} # script name -> full path for p in paths: for fn in glob.glob(p + u"*.py"): if os.path.isfile(fn): # Discard previous plugin with same name sn = os.path.basename(fn) plugins[sn] = fn return sorted(plugins.values())
def find_plugins(): """ return (list of str): list of the filenames of the plugins available """ hf = get_home_folder() # Order of paths matters, so that the user can override a system plugin if os.name == "nt": # Typically, on Windows, the odemis package is a single file located into # a dedicated OdemisViewer folder which contains also all the dependencies # => search inside this folder paths = (os.path.join(odemis.__path__[0], u"..", u"plugins"), # There is no official place for putting per-user system # overriding file, so just put with the config file. os.path.join(hf, u".config", u"odemis", u"plugins") ) else: # hopefully this is Linux paths = (u"/usr/lib/odemis/plugins", u"/usr/local/lib/odemis/plugins", os.path.join(hf, u".local/share/odemis/plugins"), ) plugins = {} # script name -> full path for p in paths: for fn in glob.glob(os.path.join(p, u"*.py")): if os.path.isfile(fn): # Discard previous plugin with same name sn = os.path.basename(fn) plugins[sn] = fn return sorted(plugins.values())
def init_logger(level=logging.DEBUG, log_file=None): """ Initializes the logger to some nice defaults To be called only once, at the initialisation """ if level <= logging.INFO: pyrolog = logging.getLogger("Pyro4") pyrolog.setLevel(min(pyrolog.getEffectiveLevel(), level)) logging.basicConfig(format=" - %(levelname)s \t%(message)s") l = logging.getLogger() l.setLevel(level) frm = "%(asctime)s\t%(levelname)s\t%(module)s:%(lineno)d:\t%(message)s" l.handlers[0].setFormatter(logging.Formatter(frm)) # Create file handler # Path to the log file logfile_path = log_file or os.path.join(get_home_folder(), LOG_FILE) file_format = logging.Formatter(frm) # Max 5 log files of 10Mb file_handler = RotatingFileHandler(logfile_path, maxBytes=10 * (2**20), backupCount=5) file_handler.setFormatter(file_format) log.addHandler(file_handler)
def init_logger(level=logging.DEBUG, log_file=None): """ Initializes the logger to some nice defaults To be called only once, at the initialisation """ if level <= logging.INFO: pyrolog = logging.getLogger("Pyro4") pyrolog.setLevel(min(pyrolog.getEffectiveLevel(), level)) logging.basicConfig(format=" - %(levelname)s \t%(message)s") l = logging.getLogger() l.setLevel(level) frm = "%(asctime)s %(levelname)-7s %(module)-15s: %(message)s" l.handlers[0].setFormatter(logging.Formatter(frm)) # Create file handler # Path to the log file logfile_path = log_file or os.path.join(get_home_folder(), LOG_FILE) # Formatting string for logging messages to file frm = "%(asctime)s %(levelname)-7s %(module)s:%(lineno)d: %(message)s" file_format = logging.Formatter(frm) # Max 5 log files of 10Mb file_handler = RotatingFileHandler(logfile_path, maxBytes=10 * (2 ** 20), backupCount=5) file_handler.setFormatter(file_format) log.addHandler(file_handler)
def test_find_plugins(self): """ Test that find_plugins can find plugin modules""" paths = plugin.find_plugins() if not paths: # A typical reason for this to fail is that no plugin are installed hf = get_home_folder() upath = os.path.join(hf, u".local/share/odemis/plugins") if not os.path.isdir(upath) or not os.listdir(upath): self.fail( "Please install at least one plugin in ~/.local/share/odemis/plugins" ) self.assertGreater(len(paths), 0)
daterev = time.strftime("%d%m%Y") timeshrt = time.strftime("%H%M") timeshrt_colon = time.strftime("%H:%M") timelng = time.strftime("%H%M%S") # date_sl = time.strftime("%Y/%m/%d") # timelng_sl = time.strftime("%H/%M/%S") current_year = time.strftime("%Y") dshrtrev = time.strftime("%d%m%y") # Note: dateshrt cannot be used in tests, as on days similar to the year, such as 20-10-20, # it's not clear what is the day and what is the year, but the code convention is to # guess DDMMYY (aka dshrtrev). # dateshrt = time.strftime("%y%m%d") dshrtrev_hyphen = time.strftime("%d-%m-%y") EXTS = ('.tiff', '.ome.tiff', '.0.ome.tiff', '.h5', '.hdf5') PATH = get_home_folder() class TestFilenameSuggestions(unittest.TestCase): """ Tests the util-acquisition functions for filename suggestions. """ def test_guess_pattern(self): fn_ptns = { 'test-123': ('test-{cnt}', '123'), '%stest-123' % date: ('{datelng}test-{cnt}', '123'), '123-test-%s' % date: ('{cnt}-test-{datelng}', '123'), 'test-123-%s' % timeshrt: ('test-{cnt}-{timeshrt}', '123'), 'test-123-%s' % timeshrt_colon: ('test-{cnt}-{timeshrt_colon}', '123'), '%s%s-acquisition' % (date, timelng):
import ConfigParser from ConfigParser import NoOptionError except ImportError: # Python 3 naming import configparser as ConfigParser from configparser import NoOptionError import logging import math import os.path from odemis.dataio import tiff from odemis.acq.align import delphi from odemis.gui.util import get_picture_folder, get_home_folder import sys from past.builtins import unicode CONF_PATH = os.path.join(get_home_folder(), u".config/odemis") ACQUI_PATH = get_picture_folder() class Config(with_metaclass(ABCMeta, object)): """ Abstract configuration super class Configurations are built around the :py:class:`ConfigParser.SafeConfigParser` class. The main difference is that the filename is fixed, and changes are automatically saved. """ @abstractproperty def file_name(self): """Name of the configuration file"""
from abc import ABCMeta, abstractproperty try: import ConfigParser from ConfigParser import NoOptionError except ImportError: # Python 3 naming import configparser as ConfigParser from configparser import NoOptionError import logging import math import os.path from odemis.dataio import tiff from odemis.acq.align import delphi from odemis.gui.util import get_picture_folder, get_home_folder CONF_PATH = os.path.join(get_home_folder(), u".config/odemis") ACQUI_PATH = get_picture_folder() class Config(object): """ Abstract configuration super class Configurations are built around the :py:class:`ConfigParser.SafeConfigParser` class. The main difference is that the filename is fixed, and changes are automatically saved. """ __metaclass__ = ABCMeta @abstractproperty
from odemis.dataio import get_available_formats import odemis.gui from odemis.gui.conf import get_acqui_conf from odemis.gui.conf import util from odemis.gui.plugin import Plugin, AcquisitionDialog from odemis.gui.util import formats_to_wildcards, get_home_folder import os.path import time import wx try: import configparser except ImportError: # Python 2 import ConfigParser as configparser CONF_FILE = os.path.join(get_home_folder(), ".config", "odemis", "cli_rgb.ini") class RGBCLIntensity(Plugin): name = "RGB CL-intensity" __version__ = "1.2" __author__ = u"Toon Coenen & Éric Piel" __license__ = "GNU General Public License 2" vaconf = OrderedDict(( ("filter1", { "label": "Blue", "choices": util.format_band_choices, }), ("filter2", { "label": "Green",