def test_convert_pdf_page_to_web(tmp_fixture_dir): """Convert single page pdf to web version""" pdf = Path(tmp_fixture_dir) / 'PDF' / PAGE_ONE # Make new file opt = convert_pdf_to_web(pdf) # Default file location assert opt == pdf.parent / 'WEB' / PAGE_ONE assert opt.exists() # Conversion changes file content assert opt.stat().st_size != pdf.stat().st_size # Calling again should not create new file mtime = opt.stat().st_mtime opt2 = convert_pdf_to_web(pdf) assert opt2.stat().st_mtime == mtime # If pdf if changed, convert should rerun pdf.touch() opt3 = convert_pdf_to_web(pdf) assert opt3.stat().st_mtime > mtime # Nonexisting file should raise error false_pdf = pdf.with_name('nonexisting') assert not false_pdf.is_file() with pytest.raises(FileNotFoundError): convert_pdf_to_web(false_pdf)
def main(): LOGGER.info("=" * 60) LOGGER.info("= Spojitr installer") LOGGER.info("=" * 60) bashrc_filepath = PosixPath("~/.bashrc").expanduser() if not bashrc_filepath.exists(): LOGGER.info("Creating file %s", bashrc_filepath) bashrc_filepath.touch(mode=0o644, exist_ok=True) install(bashrc_filepath)
def lock(path: pathlib.PosixPath): """Creates a lock file, a file protected from beeing used by other processes. (The lock file isn't the same as the file of the passed path.) Args: path (pathlib.PosixPath): path to the file """ path = path.with_suffix('.lock') if not path.exists(): path.touch() with path.open("r+") as lock_file: try: fcntl.lockf(lock_file.fileno(), fcntl.LOCK_EX) yield lock_file finally: fcntl.lockf(lock_file.fileno(), fcntl.LOCK_UN)
""" cli.config ~~~~~~~~~~~~ This module implements interface for getting and setting the "ledge" cli application's configuration. The configuration is stored in the .config.yaml file """ import yaml from pathlib import PosixPath config_file = PosixPath('.config.yaml') if not config_file.exists(): config_file.touch() def get(key): """Get the config value by providing the key""" with config_file.open('r') as f: conf = yaml.load(f) return conf.get(key) return None def set(key, value): """Set a config by providine a key-value pair""" with config_file.open('r') as f: conf = yaml.load(f) if conf is None: conf = dict()