コード例 #1
0
ファイル: inputsetters.py プロジェクト: 4xxi/resonances
def set_time_interval(from_day: float, to_day: float):
    """
    Sets start time and stop time to param.in file.
    :param from_day:
    :param to_day:
    :return:
    """
    def _edit_file(filepath: str, callback: Callable[[Iterable[str], TextIO], None]):
        with open(filepath) as f:
            out_fname = filepath + ".tmp"
            out = open(out_fname, "w")
            callback(f, out)
            out.close()
            os.rename(out_fname, filepath)

    def _update_params(infile: Iterable[str], outfile: TextIO):
        startday_pattern = ' start time (days)= '
        stopday_pattern = ' stop time (days) = '
        for line in infile:
            if line.startswith(startday_pattern):
                line = '%s%f\n' % (startday_pattern, from_day)
            if line.startswith(stopday_pattern):
                line = '%s%f\n' % (stopday_pattern, to_day)
            outfile.write(line)

    integrator_path = opjoin(Config.get_project_dir(), CONFIG['integrator']['dir'])
    param_in_filepath = opjoin(integrator_path, CONFIG.INTEGRATOR_PARAM_FILENAME)

    _edit_file(param_in_filepath, _update_params)
コード例 #2
0
ファイル: __init__.py プロジェクト: 4xxi/resonances
from .facades import PhaseCountException
from .collection import OrbitalElementSet

from os.path import exists as opexists
from os.path import join as opjoin
from os.path import isabs
from os import makedirs
import glob
from tarfile import is_tarfile
from tarfile import open as taropen
import os
from settings import Config
import shutil
from os.path import basename

PROJECT_DIR = Config.get_project_dir()
CONFIG = Config.get_params()
_ex_folder = CONFIG['extract_dir']
EXTRACT_PATH = _ex_folder if isabs(_ex_folder) else opjoin(PROJECT_DIR, _ex_folder)

BUCKET = CONFIG['s3']['bucket']
_s3_folder = CONFIG['s3files_dir']
S3_FILES_DIR = _s3_folder if isabs(_s3_folder) else opjoin(PROJECT_DIR, _s3_folder)


class FilepathException(Exception):
    pass


class FilepathInvalidException(Exception):
    pass
コード例 #3
0
ファイル: dbutills.py プロジェクト: 4xxi/resonances
    logger = logging.getLogger("myapp.sqltime")
    logger.setLevel(logging.DEBUG)

    @event.listens_for(Engine, "before_cursor_execute")
    def before_cursor_execute(conn, cursor, statement, parameters, context, executemany):
        conn.info.setdefault('query_start_time', []).append(time.time())
        logger.debug("Start Query: %s", statement % parameters)

    @event.listens_for(Engine, "after_cursor_execute")
    def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
        total = time.time() - conn.info['query_start_time'].pop(-1)
        logger.debug("Query Complete!")
        logger.debug("Total Time: %f", total)

_config = AlembicConfig(os.path.join(
    Config.get_project_dir(), Config.get_params()['db_path']
))


@as_declarative()
class Base(object):
    def __init__(self, **kwargs):
        super(Base, self).__init__(**kwargs)
    id = Column(Integer, primary_key=True)

engine = create_engine('postgres://%s:%s@%s/%s' % (_USER, _PASSWORD, _HOST, _DB))
_Session = sessionmaker()
_Session.configure(bind=engine)
session = _Session()    # type: Session

_conn = redis.ConnectionPool(