def _write_to_files(work_dir, job_lnames):
    '''
    Wrapper function around this internal write process.
    Triggers the write-back to the files to the mem cache.

    @param work_dir: where shall the files be stored?
    @type work_dir: string
    @param job_lnames: list of names
    @type job_lnames: list
    '''
    bibtask.task_update_progress('Writing to files in %s' % (work_dir))
    bibtask.write_message("Writing cluster with %s entries to "
                          "files in %s"
                          % (len(dat.RELEVANT_RECORDS), work_dir,),
                            stream=sys.stdout, verbose=0)

    if not os.path.exists(work_dir):
        os.mkdir(work_dir)

    write_mem_cache_to_files(work_dir, job_lnames)
    dat.reset_mem_cache(True)
def _write_to_files(work_dir, job_lnames):
    '''
    Wrapper function around this internal write process.
    Triggers the write-back to the files to the mem cache.

    @param work_dir: where shall the files be stored?
    @type work_dir: string
    @param job_lnames: list of names
    @type job_lnames: list
    '''
    bibtask.task_update_progress('Writing to files in %s' % (work_dir))
    bibtask.write_message("Writing cluster with %s entries to "
                          "files in %s" % (
                              len(dat.RELEVANT_RECORDS),
                              work_dir,
                          ),
                          stream=sys.stdout,
                          verbose=0)

    if not os.path.exists(work_dir):
        os.mkdir(work_dir)

    write_mem_cache_to_files(work_dir, job_lnames)
    dat.reset_mem_cache(True)
def main():
    """Main function """
    arguments = sys.argv

    if len(arguments) <= 1:
        bconfig.LOGGER.error("Please provide parameters!")
        _display_help()

    run_daemon = True
    standalone_option = ("-S", "--standalone", "-j", "--job-dir")

    for option in standalone_option:
        for arg in arguments:
            if arg.startswith(option):
                run_daemon = False

    if run_daemon:
        daemon = None
        try:
            import bibauthorid_daemon as daemon
        except ImportError:
            bconfig.LOGGER.error("Hmm...No Daemon process running.")

        if daemon:
            daemon.bibauthorid_daemon()
    else:
        options = _read_options(arguments)

        if options["job_dir"]:
            job_dir = options["job_dir"]

            if job_dir.endswith("/"):
                job_dir = job_dir[0:-1]

            log_name = osp.abspath(job_dir).split("/")
            logfile = "%s/%s.log" % (job_dir, log_name[-1])

            start = time.time()

            bconfig.init_logger(logfile)
            populate_structs_from_files(job_dir)

            bconfig.LOGGER.debug("| Loaded %s records."
                                 % len(dat.RELEVANT_RECORDS))

            engine.start_computation(process_doclist=True,
                             process_orphans=True,
                             print_stats=True)

            result_path = "%s/results/" % (job_dir,)

            if make_directory(result_path):
                write_mem_cache_to_files(result_path, is_result=True)
            else:
                bconfig.LOGGER.error("Cannot write to destination: "
                                     "Cannot create directory")

            end = time.time() - start

            bconfig.LOGGER.log(25, "Finish! The computation finished in %.2fs"
                               % (end))
            bconfig.stop_and_close_logger()
        else:
            bconfig.LOGGER.error("Standalone mode without parameters "
                                 "does not do anything helpful. Please"
                                 "consult -h help message for usage")
Esempio n. 4
0
def main():
    """Main function """
    arguments = sys.argv

    if len(arguments) <= 1:
        bconfig.LOGGER.error("Please provide parameters!")
        _display_help()

    run_daemon = True
    standalone_option = ("-S", "--standalone", "-j", "--job-dir")

    for option in standalone_option:
        for arg in arguments:
            if arg.startswith(option):
                run_daemon = False

    if run_daemon:
        daemon = None
        try:
            import bibauthorid_daemon as daemon
        except ImportError:
            bconfig.LOGGER.error("Hmm...No Daemon process running.")

        if daemon:
            daemon.bibauthorid_daemon()
    else:
        options = _read_options(arguments)

        if options["job_dir"]:
            job_dir = options["job_dir"]

            if job_dir.endswith("/"):
                job_dir = job_dir[0:-1]

            log_name = osp.abspath(job_dir).split("/")
            logfile = "%s/%s.log" % (job_dir, log_name[-1])

            start = time.time()

            bconfig.init_logger(logfile)
            populate_structs_from_files(job_dir)

            bconfig.LOGGER.debug("| Loaded %s records." %
                                 len(dat.RELEVANT_RECORDS))

            engine.start_computation(process_doclist=True,
                                     process_orphans=True,
                                     print_stats=True)

            result_path = "%s/results/" % (job_dir, )

            if make_directory(result_path):
                write_mem_cache_to_files(result_path, is_result=True)
            else:
                bconfig.LOGGER.error("Cannot write to destination: "
                                     "Cannot create directory")

            end = time.time() - start

            bconfig.LOGGER.log(
                25, "Finish! The computation finished in %.2fs" % (end))
            bconfig.stop_and_close_logger()
        else:
            bconfig.LOGGER.error("Standalone mode without parameters "
                                 "does not do anything helpful. Please"
                                 "consult -h help message for usage")