示例#1
0
def save_data_to_server():
    if flask.request.method == 'POST':
        process_uuid = flask.request.form['process_uuid']
        data_name = flask.request.form['data_name']
        saved_data = eval(flask.request.form['saved_data'])
    else:
        raise RuntimeError

    data_dir_to_save = os.path.join(
        get_loom_dir(),
        'data',
        data_name,
    )
    if os.path.exists(data_dir_to_save):
        msg = ('Data with name "{}" already exists, '
               'chose a different name.'.format(data_name))
    else:
        os.makedirs(data_dir_to_save)
        full_data_dir = get_full_data_dir(
            process_uuid=process_uuid,
            saved_data=saved_data,
        )
        files_to_copy = get_data_file_path_list(full_data_dir)
        for src in files_to_copy:
            # shutil.copy(src, data_dir_to_save)
            shutil.move(src, data_dir_to_save)
        msg = 'Data successfully saved as "{}".'.format(data_name)

    return flask.render_template(
        'save_message.html',
        msg=msg,
    )
示例#2
0
def get_cache_dir(process_uuid):
    cache_dir = os.path.join(
        get_loom_dir(),
        LOOM_CACHE_DIR,
        process_uuid,
    )
    return cache_dir
示例#3
0
def load(n_processes=None):
    # XXX: n_processes is a string.
    if n_processes is None:
        n_processes_val = DEFAULT_NUM_PROCESSES
    else:
        n_processes_val = eval(n_processes)

    if flask.request.method == 'GET':
        full_data_directories = glob.glob(
            os.path.join(
                get_loom_dir(),
                'data',
                "*",
            ))
        full_data_directories.sort()
        data_names = [
            os.path.split(full_data_dir)[1]
            for full_data_dir in full_data_directories
        ]

    return flask.render_template(
        'load.html',
        data_names=data_names,
        n_processes=n_processes_val,
    )
示例#4
0
def get_loom_config(request_dict=None, logger_name=get_logger_name()):
    logger = logging.getLogger(logger_name)

    default_config_file = os.path.join(
        get_loom_dir(),
        'config/default.ini',
    )
    loom_config = LoomConfig(
        file_path=default_config_file,
        logger_name=logger_name,
    )

    if request_dict is not None:
        # Update config with form data.
        root_system = request_dict['type'] + request_dict['rank']
        for section in loom_config.parser.sections():
            for option in loom_config.parser.options(section):
                try:
                    if option == 'root_system':
                        value = root_system
                    else:
                        value = request_dict[option]
                    if (section == 'numerical parameters' or value == 'None'):
                        loom_config[option] = eval(value)
                    else:
                        loom_config[option] = value
                    loom_config.parser.set(section, option, value)
                except KeyError:
                    logger.warning(
                        'No entry for option = {}, skip it.'.format(option))
                    pass

    return loom_config
示例#5
0
def get_logging_file_path(logger_name):
    logging_file_path = os.path.join(
        get_loom_dir(),
        ('logs/{}_{}-{:02}-{:02} {:02}:{:02}:{:02}.log'.format(
            logger_name,
            *time.localtime(time.time())[:6])),
    )
    return logging_file_path
示例#6
0
def get_full_data_dir(
    process_uuid=None,
    data_name=None,
    saved_data=None,
):
    if saved_data is True:
        if data_name is None:
            raise RuntimeError
        full_data_dir = os.path.join(get_loom_dir(), 'data', data_name)
    else:
        if process_uuid is None:
            raise RuntimeError
        full_data_dir = get_cache_dir(process_uuid)

    return full_data_dir
示例#7
0
def config(n_processes=None):
    # XXX: n_processes is a string.
    loom_config = None
    event_source_url = None
    text_area_content = ''
    process_uuid = None

    if flask.request.method == 'GET':
        # Load the default configuration.
        loom_config = get_loom_config()
        if n_processes is None:
            n_processes_val = DEFAULT_NUM_PROCESSES
        else:
            n_processes_val = eval(n_processes)

    elif flask.request.method == 'POST':
        if n_processes is None:
            n_processes_val = eval(flask.request.form['n_processes'])
        else:
            n_processes_val = eval(n_processes)

        try:
            uploaded_config_file = flask.request.files['config_file']
        except KeyError:
            uploaded_config_file = None

        try:
            data_name = flask.request.form['data_name']
        except KeyError:
            data_name = None

        if uploaded_config_file is not None:
            # Load configuration from the uploaded file.
            if uploaded_config_file.filename == '':
                # Load button clicked without a selected file.
                # Load the default configuration.
                loom_config = get_loom_config()
            else:
                loom_config = LoomConfig(logger_name=get_logger_name())
                loom_config.read(uploaded_config_file)
        elif data_name is not None:
            config_file_path = os.path.join(
                get_loom_dir(),
                'data',
                data_name,
                'config.ini',
            )
            loom_config = LoomConfig(
                file_path=config_file_path,
                logger_name=get_logger_name(),
            )

    return flask.render_template(
        'config.html',
        config_options=config_options,
        advanced_config_options=advanced_config_options,
        loom_config=loom_config,
        n_processes=n_processes_val,
        process_uuid=process_uuid,
        event_source_url=event_source_url,
        text_area_content=text_area_content,
    )
示例#8
0
matplotlib.rcParams['figure.figsize'] = [8.0, 8.0]
matplotlib.rcParams['savefig.format'] = 'pdf'
matplotlib.rcParams['savefig.bbox'] = 'tight'
matplotlib.rcParams['savefig.pad_inches'] = 0.0
# matplotlib.rcParams['text.usetex'] = True

from api import get_loom_dir
from api import set_logging
from api import generate_spectral_network as generate
from api import load_spectral_network as load
from api import save_spectral_network as save
from api import make_spectral_network_plot as plot
from api import load_config, save_config

LOGGING_FILE_PATH = os.path.join(
    get_loom_dir(),
    ('logs/loom_{}-{:02}-{:02} {:02}:{:02}:{:02}.log'.format(
        *time.localtime(time.time())[:6])),
)

set_logging(
    logger_name='loom',
    logging_level_name='INFO',
    logging_stream=sys.stdout,
    logging_file_name=LOGGING_FILE_PATH,
)

__all__ = [
    'config',
    'gui',
    'intersection',