Пример #1
0
def test_cfgNewConfigDef():
    ch = ExpConfigHandler(pathscheme='test1')
    #ch.addNewConfig("/home/scholer/Documents/labfluence_data_testsetup/.labfluence/templates.yml", "templates")
    # I have added the following to the 'exp' config:
    # config_define_new:
    #   templates: ./.labfluence/templates.yml
    logger.info("ch.get('exp_subentry_template'): %s", ch.get('exp_subentry_template'))
Пример #2
0
def notestExpConfig1():
    ch = ExpConfigHandler(pathscheme='test1')
    logger.info("ch.HierarchicalConfigHandler.Configs: %s", ch.HierarchicalConfigHandler.printConfigs())
    path = "/home/scholer/Documents/labfluence_data_testsetup/2013_Aarhus/RS102 Strep-col11 TR annealed with biotin"
    cfg = ch.loadExpConfig(path)
    if cfg is None:
        logger.info("cfg is None; using empty dict.")
        cfg = dict()
    cfg['test_key'] = datetime.now().strftime("%Y%m%d-%H%M%S") # you can use strptime to parse a formatted date string.
    logger.info("Saving config for path '%s'", path)
    ch.saveExpConfig(path)
Пример #3
0
 def test_configTypeChain():
     #ch2 = ExpConfigHandler('../test/config/system_config.yml')
     ch2 = self.Confighandler
     logger.info('ch2.Configs:\n{}'.format(ch2.Configs))
     ch2.Configs
     ch2.Configs['system']['user_config_path'] = os.path.join(
         configtestdir, 'user_config.yml')
     ch2.saveConfigs()
     ch3 = ExpConfigHandler('../test/config/system_config.yml')
     logger.info('ch3.Configs:\n{}'.format(ch3.Configs))
Пример #4
0
    def setUp():
        scriptdir = os.path.dirname(os.path.abspath(__file__))
        configtestdir = os.path.join(scriptdir, '../test/config')
        paths = [
            os.path.join(configtestdir, cfg)
            for cfg in ('system_config.yml', 'user_config.yml',
                        'exp_config.yml')
        ]
        self.Confighandler = ch = ExpConfigHandler(*paths)
        logger.info("End ch confighandler init...")

        def printPaths():
            logger.info("os.path.curdir:            %s", os.path.curdir)
            logger.info("os.path.realpath(curdir) : %s",
                        os.path.realpath(os.path.curdir))
            logger.info("os.path.abspath(__file__): %s",
                        os.path.abspath(__file__))
            #print "os.path.curdir: {}".format(os.path.curdir)

        printPaths()
        return ch
Пример #5
0
    def __init__(self, confighandler=None):
        #self.ActiveExperiments = list() # Probably better to use a property attribute
        #self.RecentExperiments = list()
        logger.info(
            ">>>>>>>>>>>>>>  Starting init of LabfluenceGUI  >>>>>>>>>>>>>>>>")

        self.Confighandler = confighandler or ExpConfigHandler(
            pathscheme='default1')
        #self.Confighandler.Singletons.setdefault('app', self)
        self.Confighandler.Singletons['app'] = self
        if 'experimentmanager' not in self.Confighandler.Singletons:
            print "LabfluenceGUI.__init__ >> Instantiating new ExperimentManager!"
            self.Confighandler.Singletons[
                'experimentmanager'] = ExperimentManager(
                    confighandler=self.Confighandler, autoinit=('localexps', ))

        #self.init_ui()
        self.tkroot = LabfluenceTkRoot(confighandler)
        logger.debug("self.tkroot initialized")
        self.Controllers = dict()
        self.ExpNotebooks = dict()
        self.init_bindings()
        self.init_fonts()
        self.connect_controllers()
Пример #6
0
def confighandler1():
    ch = ExpConfigHandler(pathscheme='test1')
    return ch
Пример #7
0
def test_registerEntryChangeCallback():
    logger.info(">>>>>>>>>>>> starting test_registerEntryChangeCallback(): >>>>>>>>>>>>>>>>>>>>")
    #registerEntryChangeCallback invokeEntryChangeCallback
    ch = ExpConfigHandler(pathscheme='test1')
    ch.setkey('testkey', 'random string')
    def printHej(who, *args):
        logger.info("hi %s, other args: %s", who, args)
    def printNej():
        logger.info("no way!")
    def argsAndkwargs(arg1, arg2, hej, der, **kwargs):
        logger.info("%s, %s, %s, %s, %s", arg1, arg2, hej, der, kwargs)
    ch.registerEntryChangeCallback('app_active_experiments', printHej, ('morten', ))
    ch.registerEntryChangeCallback('app_recent_experiments', printNej)
    ch.registerEntryChangeCallback('app_recent_experiments', argsAndkwargs, ('word', 'up'), dict(hej='tjubang', der='sjubang', my='cat'))
    ch.ChangedEntriesForCallbacks.add('app_active_experiments')
    ch.ChangedEntriesForCallbacks.add('app_recent_experiments')

    logger.info("Round one:")
    ch.invokeEntryChangeCallback('app_active_experiments')
    ch.invokeEntryChangeCallback() # invokes printNej and argsAndkwargs
    logger.info("Round two:")
    ch.invokeEntryChangeCallback('app_active_experiments') # still invokes printHej
    ch.invokeEntryChangeCallback() # does not invoke anything...

    logger.info("<<<<<<<<<<<<< completed test_registerEntryChangeCallback(): <<<<<<<<<<<<<<<<<<<<")
Пример #8
0
def test_addNewConfig():
    ch = ExpConfigHandler(pathscheme='test1')
    ch.addNewConfig("/home/scholer/Documents/labfluence_data_testsetup/.labfluence/templates.yml", "templates")
    logger.info("ch.get('exp_subentry_template'): %s", ch.get('exp_subentry_template'))
Пример #9
0
    def __init__(self, pathscheme=None, enableHierarchy=False, readfiles=False):
        ExpConfigHandler.__init__(self, pathscheme=pathscheme, enableHierarchy=False, readfiles=False)

        expconfigyaml = r"""
exp_series_dir_fmt: '{expid} {exp_titledesc}'
exp_series_regex: (?P<expid>RS[0-9]{3})[_ ]+(?P<exp_titledesc>.+)
exp_subentry_dir_fmt: '{expid}{subentry_idx} {subentry_titledesc} ({datetime:%Y%m%d})'
exp_subentry_regex: (?P<date1>[0-9]{8})?[_ ]*(?P<expid>RS[0-9]{3})-?(?P<subentry_idx>[^_
  ])[_ ]+(?P<subentry_titledesc>.+?)\s*(\((?P<date2>[0-9]{8})\))?$
exp_subentry_regex_old: (?P<date1>[0-9]{8})?[_ ]*(?P<expid>RS[0-9]{3})-?(?P<subentry_idx>[^_ ])[_ ]+(?P<subentry_titledesc>.+?)\s?(\((?P<date2>[0-9]{8})\))?$
exp_subentryid_fmt: '{expid}{subentry_idx}'
expid_fmt: RS{exp_series_index:03d}
expid_regex: RS(?P<exp_series_index>[0-9]{3,4})
journal_entry_fmt: '[{datetime:%Y%m%d %H:%M:%S}] {text}'
journal_subentry_token_fmt_obsolete: '<p id="{}"></p>'
journal_date_format: '%Y%m%d'
local_exp_ignoreDirs:
- equipment_data_sync
- 2008-2010_Aarhus
- 2011_Aarhus
- 2012_Aarhus
- 2012_Harvard
local_exp_rootDir: .
local_exp_subDir: ./2013_Aarhus
wiki_exp_root_spaceKey: ~scholer
wiki_exp_root_pageId: '524296'
wiki_exp_archive_pageId: '524308'
wiki_exp_new_subentry_token: <h2>Results and discussion</h2>
wiki_exp_new_subentry_insert_regex_fmt: (?P<before_insert><h2>Experimental section</h2>.*?)(?P<after_insert><h4>{expid}[_-]?[{next_subentry_idx}-z].*?</h4>|<h[1-3]>.*?</h[1-3]>|$)
wiki_journal_entry_insert_regex_fmt: '(?P<before_insert><h2>Experimental section</h2>.*?<h4>{expid}{subentry_idx}.*?</h4>.*?)(?P<after_insert><h[1-4]>.+?</h[1-4]>|$)'
wiki_subentry_parse_regex_fmt: '(?P<exp_section_header><h2>Experimental section</h2>).*?(?P<subentry_header><h4>{expid}{subentry_idx}.+?</h4>)(?P<subentry_xhtml>.*?)(?P<next_header><h[1-4]>.+?</h[1-4]>|$)'
wiki_templates_pageIds:
  exp_page: '524303'
  exp_subentry: '524306'
wiki_template_string_interpolation_mode: 'old'
wiki_template_string_interpolation_mode_comment: can be 'new', 'old' and 'template'. 'new' is curly-braced based string.format; 'old' is %-based moduli substitution and 'template' uses string templates only.
wiki_allow_template_caching: true
wiki_default_newpage_template: 'exp_page'
"""
        userconfigyaml = """
app_active_experiments:
- RS102
- RS134
- RS135
app_recent_experiments:
- RS103
crypt_iv: Ko8E4tmJP7SCgLla
wiki_serverparams:
  baseurl: http://10.14.40.245:8090
wiki_username: scholer
wiki_lims_pageid: '917542'
"""
        # Consider switching to using the 'test1' config, even for this...
        # Well, on the other hand... The fake objects are not supposed to touch anything, used for testing.
        configyamls = dict(user=userconfigyaml, exp=expconfigyaml)
        for cfg, yml in configyamls.items():
            newconfig = yaml.load(yml)
            self.Configs.setdefault(cfg, dict()).update(newconfig) # 1-liner, replacing the four below:
            #if cfg in self.Configs:
            #    self.Configs[cfg].update(newconfig)
            #else:
            #    self.Configs[cfg] = newconfig
            logger.debug("Config '%s' loaded (using hard-coded test configuration...).", cfg)
        self.__expconfigs = dict()
Пример #10
0
 def setUp():
     self.Confighandler = ch = ExpConfigHandler(pathscheme='test1')
Пример #11
0
 def setUp():
     self.Confighandler = ch = ExpConfigHandler(pathscheme='test1')
     self.Pathfinder = pf = PathFinder(VERBOSE=10)
Пример #12
0
        logging.getLogger("tkui.mainframe").setLevel(logging.DEBUG)
        logging.getLogger(__name__).setLevel(logging.DEBUG)
        logger.debug("Loggers setting to debug level...")

        pathscheme = argsns.pathscheme or 'test1'

        logger.info( "Enabling testing environment..." )
        confighandler = FakeConfighandler(pathscheme=pathscheme)
        # set basedir for exp:
        confighandler.ConfigPaths['exp'] = os.path.join('tests', 'test_data', 'test_filestructure', 'labfluence_data_testsetup', '.labfluence.yml')
        server = FakeConfluenceServer(confighandler=confighandler)

    else:
        logger.debug(" >>>>>> Initiating real confighandler and server... >>>>>>")
        pathscheme = argsns.pathscheme or 'default1'
        confighandler = ExpConfigHandler(pathscheme='default1')
        try:
            logger.debug("Confighandler instantiated, Initiating server... >>>>>>")
            # setting autologin=False during init should defer login attempt...
            server = ConfluenceXmlRpcServer(autologin=False, confighandler=confighandler)
            server._autologin = True
        except socket.error as e:
            logger.error( "Socket error during server init ('%s'). This should not happen; autologin is shielded by try-clause.", e)
            server = None

    confighandler.Singletons['server'] = server
    logger.debug(" >>>>>> Server instantiated, initiating ExperimentManager... >>>>>> ")
    manager = ExperimentManager(confighandler=confighandler, autoinit=('localexps', ))
    confighandler.Singletons['experimentmanager'] = manager
    logger.debug(" >>>>>> ExperimentManager instantiated, starting LabfluenceApp... >>>>>>")
Пример #13
0
def main():

    ##############################
    ###### Parse arguments: ######
    ##############################

    #argsns = parser.parse_args() # produces a namespace, not a dict.
    argsns = parse_args()

    #######################################
    ### Set up standard logging system ####
    #######################################
    loghandlers = init_logging(argsns, prefix="labfluence_cmd")

    ############################
    #### Set up logging:    ####
    ############################
    #logfmt = "%(levelname)s %(name)s:%(lineno)s %(funcName)s() > %(message)s"
    #try:
    #    loglevel = int(argsns.loglevel)
    #except ValueError:
    #    loglevel = argsns.loglevel.upper()
    ##logfmt = "%(levelname)s:%(name)s: %(funcName)s() :: %(message)s"
    #if argsns.debug is None:
    #    #and 'all' in argsns.debug:
    #    logging.basicConfig(level=loglevel, format=logfmt)
    ## argsns.debug is a list (possibly empty)
    #elif argsns.debug:
    ## argsns.debug is a non-empty list
    #    logging.basicConfig(level=loglevel, format=logfmt)
    #    for mod in argsns.debug:
    #        logger.info("Enabling logging debug messages for module: %s", mod)
    #        logging.getLogger(mod).setLevel(logging.DEBUG)
    #else:
    #    # argsns.debug is an empty list
    #    logging.basicConfig(level=min(logging.DEBUG, loglevel), format=logfmt)
    #logging.getLogger("__main__").setLevel(logging.DEBUG)

    #
    #if argsns.logtofile or True: # always log for now...
    #    # based on http://docs.python.org/2/howto/logging-cookbook.html
    #    if not os.path.exists('logs'):
    #        os.mkdir('logs')
    #    if argsns.testing:
    #        fh = logging.FileHandler('logs/labfluence_cmd_testing.log')
    #    else:
    #        fh = logging.FileHandler('logs/labfluence_cmd_debug.log')
    #    fh.setLevel(logging.DEBUG)
    #    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    #    fh.setFormatter(formatter)
    #    logging.getLogger('').addHandler(fh)  #  logging.root == logging.getLogger('')

    ####################################################################################
    # Set up confighandler, etc (depending on whether testing mode is requested...) ####
    ####################################################################################
    if argsns.testing:
        logging.getLogger(
            "model.model_testdoubles.fake_confighandler").setLevel(
                logging.DEBUG)
        logging.getLogger("model.model_testdoubles.fake_server").setLevel(
            logging.DEBUG)
        logging.getLogger(__name__).setLevel(logging.DEBUG)
        pathscheme = argsns.pathscheme or 'test1'
        logger.info("Enabling testing environment...:")
        confighandler = FakeConfighandler(pathscheme=pathscheme)
        # set basedir for exp:
        confighandler.ConfigPaths['exp'] = os.path.join(
            'tests', 'test_data', 'test_filestructure',
            'labfluence_data_testsetup', '.labfluence.yml')
        confserver = FakeConfluenceServer(confighandler=confighandler)
    else:
        pathscheme = argsns.pathscheme or 'default1'
        confighandler = ExpConfigHandler(pathscheme=pathscheme)
        try:
            confserver = ConfluenceXmlRpcServer(autologin=True,
                                                confighandler=confighandler)
        except socket.error:
            print "This should not happen; autologin is shielded by try-clause. Perhaps network issues?"
            exit(1)

    confighandler.Singletons['server'] = confserver

    # Test if default func is defined after parsing:
    func = getattr(argsns, 'func', None)
    if func:
        logger.debug("Executing function %s with argsns %s", func, argsns)
        ret = func(argsns)
    else:
        logger.error("No func specified...?")
Пример #14
0
        #logging.getLogger("tkui.views.lims_frame").setLevel(logging.DEBUG)
        logging.getLogger(__name__).setLevel(logging.DEBUG)
        logger.debug("Loggers setting to debug level...")
        pathscheme = argsns.pathscheme or 'test1'
        logger.info("Enabling testing environment...")
        confighandler = FakeConfighandler(pathscheme=pathscheme)
        # set basedir for exp:
        confighandler.ConfigPaths['exp'] = os.path.join(
            'tests', 'test_data', 'test_filestructure',
            'labfluence_data_testsetup', '.labfluence.yml')
        server = FakeConfluenceServer(confighandler=confighandler)
    else:
        logger.debug(
            ">>>>>> Initiating real confighandler and server... >>>>>>")
        pathscheme = argsns.pathscheme or 'default1'
        confighandler = ExpConfigHandler(pathscheme=argsns.pathscheme)
        logger.debug(
            "<<<<< Confighandler instantiated, Initiating server... >>>>>")
        # setting autologin=False during init should defer login attempt...
        server = ConfluenceXmlRpcServer(autologin=False,
                                        confighandler=confighandler)
        server._autologin = True

    # Init server and application:
    confighandler.Singletons['server'] = server
    logger.debug("<<<<< Server instantiated, starting LimsApp... >>>>>")
    limsapp = LimsApp(confighandler)
    logger.debug("LimsApp instantiated, adding files: %s", argsns.files)
    limsapp.FilesToAdd = argsns.files
    #limsapp.addEntriesForFiles(argsns.files)
Пример #15
0
    import argparse
    parser = argparse.ArgumentParser(
        description="Script for persisting server data.")
    parser.add_argument('--outputfn',
                        help="Start labfluence in testing environment.")
    argsns = parser.parse_args()
    outputfn = argsns.outputfn or "fakeserver_testdata_large.yml"

    outputfn = os.path.join(os.path.dirname(__file__), outputfn)

    logfmt = "%(levelname)s:%(name)s:%(lineno)s %(funcName)s():\n%(message)s\n"
    logfmt = "%(levelname)s:%(name)s:%(lineno)s %(funcName)s(): %(message)s\n"
    logging.basicConfig(level=logging.INFO, format=logfmt)
    logging.getLogger("__main__").setLevel(logging.DEBUG)

    ch = ExpConfigHandler(pathscheme='test1')
    server = ConfluenceXmlRpcServer(confighandler=ch)

    ### IMPORT PAGES and attachment (info) ###
    pagesummaries = server.getPages('~scholer')
    pages, comments, attachments = dict(), dict(), dict()

    for i, summary in enumerate(pagesummaries):
        print("Retrieving page {} of {}".format(i, len(pagesummaries)))
        pid = summary['id']
        if pid in pages:
            logger.warning(
                "Duplicate pageId! - This is already in the pages dict: '%s'",
                pid)
        p = server.getPage(pid)
        if p:
Пример #16
0
    def __init__(self,
                 pathscheme=None,
                 enableHierarchy=False,
                 readfiles=False):
        ExpConfigHandler.__init__(self,
                                  pathscheme=pathscheme,
                                  enableHierarchy=False,
                                  readfiles=False)

        expconfigyaml = r"""
exp_series_dir_fmt: '{expid} {exp_titledesc}'
exp_series_regex: (?P<expid>RS[0-9]{3})[_ ]+(?P<exp_titledesc>.+)
exp_subentry_dir_fmt: '{expid}{subentry_idx} {subentry_titledesc} ({datetime:%Y%m%d})'
exp_subentry_regex: (?P<date1>[0-9]{8})?[_ ]*(?P<expid>RS[0-9]{3})-?(?P<subentry_idx>[^_
  ])[_ ]+(?P<subentry_titledesc>.+?)\s*(\((?P<date2>[0-9]{8})\))?$
exp_subentry_regex_old: (?P<date1>[0-9]{8})?[_ ]*(?P<expid>RS[0-9]{3})-?(?P<subentry_idx>[^_ ])[_ ]+(?P<subentry_titledesc>.+?)\s?(\((?P<date2>[0-9]{8})\))?$
exp_subentryid_fmt: '{expid}{subentry_idx}'
expid_fmt: RS{exp_series_index:03d}
expid_regex: RS(?P<exp_series_index>[0-9]{3,4})
journal_entry_fmt: '[{datetime:%Y%m%d %H:%M:%S}] {text}'
journal_subentry_token_fmt_obsolete: '<p id="{}"></p>'
journal_date_format: '%Y%m%d'
local_exp_ignoreDirs:
- equipment_data_sync
- 2008-2010_Aarhus
- 2011_Aarhus
- 2012_Aarhus
- 2012_Harvard
local_exp_rootDir: .
local_exp_subDir: ./2013_Aarhus
wiki_exp_root_spaceKey: ~scholer
wiki_exp_root_pageId: '524296'
wiki_exp_archive_pageId: '524308'
wiki_exp_new_subentry_token: <h2>Results and discussion</h2>
wiki_exp_new_subentry_insert_regex_fmt: (?P<before_insert><h2>Experimental section</h2>.*?)(?P<after_insert><h4>{expid}[_-]?[{next_subentry_idx}-z].*?</h4>|<h[1-3]>.*?</h[1-3]>|$)
wiki_journal_entry_insert_regex_fmt: '(?P<before_insert><h2>Experimental section</h2>.*?<h4>{expid}{subentry_idx}.*?</h4>.*?)(?P<after_insert><h[1-4]>.+?</h[1-4]>|$)'
wiki_subentry_parse_regex_fmt: '(?P<exp_section_header><h2>Experimental section</h2>).*?(?P<subentry_header><h4>{expid}{subentry_idx}.+?</h4>)(?P<subentry_xhtml>.*?)(?P<next_header><h[1-4]>.+?</h[1-4]>|$)'
wiki_templates_pageIds:
  exp_page: '524303'
  exp_subentry: '524306'
wiki_template_string_interpolation_mode: 'old'
wiki_template_string_interpolation_mode_comment: can be 'new', 'old' and 'template'. 'new' is curly-braced based string.format; 'old' is %-based moduli substitution and 'template' uses string templates only.
wiki_allow_template_caching: true
wiki_default_newpage_template: 'exp_page'
"""
        userconfigyaml = """
app_active_experiments:
- RS102
- RS134
- RS135
app_recent_experiments:
- RS103
crypt_iv: Ko8E4tmJP7SCgLla
wiki_serverparams:
  baseurl: http://10.14.40.245:8090
wiki_username: scholer
wiki_lims_pageid: '917542'
"""
        # Consider switching to using the 'test1' config, even for this...
        # Well, on the other hand... The fake objects are not supposed to touch anything, used for testing.
        configyamls = dict(user=userconfigyaml, exp=expconfigyaml)
        for cfg, yml in configyamls.items():
            newconfig = yaml.load(yml)
            self.Configs.setdefault(cfg, dict()).update(
                newconfig)  # 1-liner, replacing the four below:
            #if cfg in self.Configs:
            #    self.Configs[cfg].update(newconfig)
            #else:
            #    self.Configs[cfg] = newconfig
            logger.debug(
                "Config '%s' loaded (using hard-coded test configuration...).",
                cfg)
        self.__expconfigs = dict()