def get_connection(bootstrap = True, log = False): global _CONNECTION if not _CONNECTION: if log: logger.info("Establishing a DataBase connection...") basepath = osp.join(osp.expanduser("~"), ".%s" % NAME) makedirs(basepath, exist_ok = True) abspath = osp.join(basepath, "db.db") _CONNECTION = DB(abspath) _CONNECTION.connect() if bootstrap: if log: logger.info("Bootstrapping DataBase...") abspath = osp.join(config.PATH["DATA"], "bootstrap.sql") buffer = read(abspath) queries = _get_queries(buffer) for query in queries: _CONNECTION.query(query) return _CONNECTION
def _update_requirements(path, package): path = osp.realpath(path) content = read(path) try: pattern = r"{package}(=={version})*".format( package=re.escape(package.name), version=re.escape(package.current_version)) lines = content.splitlines() nlines = len(lines) with open(path, "w") as f: for i, line in enumerate(lines): if re.search(pattern, line, flags=re.IGNORECASE): line = line.replace("==%s" % package.current_version, "==%s" % package.latest_version) f.write(line) if i < nlines - 1: f.write("\n") except Exception: # In case we f****d up! write(path, content, force=True)
def get_connection(bootstrap = True, log = False): global _CONNECTION if not _CONNECTION: if log: logger.info("Establishing a DataBase connection...") basepath = PATH["CACHE"] makedirs(basepath, exist_ok = True) abspath = osp.join(basepath, "db.db") _CONNECTION = DB(abspath) _CONNECTION.connect( detect_types = sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES ) if bootstrap: if log: logger.info("Bootstrapping DataBase...") abspath = osp.join(config.PATH["DATA"], "bootstrap.sql") buffer = read(abspath) queries = _get_queries(buffer) for query in queries: _CONNECTION.query(query) return _CONNECTION
def test_read(tmpdir): directory = tmpdir.mkdir("tmp") tempfile = directory.join("foobar.txt") tempfile.write("foobar") assert tempfile.read() == read(str(tempfile)) tempfile = directory.join("barfoo.txt") tempfile.write(\ """ foobar \n barfoo """ ) assert tempfile.read() == read(str(tempfile))
def get_connection(bootstrap=True): global _CONNECTION if not _CONNECTION: basepath = osp.join(osp.expanduser("~"), ".%s" % NAME) makedirs(basepath, exist_ok=True) abspath = osp.join(basepath, "db.db") _CONNECTION = DB(abspath) _CONNECTION.connect() if bootstrap: abspath = osp.join(config.PATH["DATA"], "bootstrap.sql") buffer = read(abspath) queries = _get_queries(buffer) for query in queries: _CONNECTION.query(query) return _CONNECTION