Esempio n. 1
0
    def sync_subdir(src_dir:Path, src_subdir:Path, target_dir:Path, ):
        """
        contents of `src_subdir` is rsynced to `target_dir`/subdir, where
            subdir is src_subdir relative to src_dir

        Example
        -------
        src_dir:    /tmp/foo/home
        src_subdir: /tmp/foo/home/assets or ./assets
        target_dir: ./dest/

        Contents of /tmp/foo/home/assets are
            synced to: dest/assets
        """

        reldir = src_subdir.relative_to(src_dir)
        _from = str(src_subdir.joinpath(src_subdir)).rstrip('/') + '/'
        _to = str(target_dir.joinpath(reldir)).rstrip('/')


        if _from == _to + '/':
            mylogger.debug(f"_from and _to are the same: {_from}", label="skip rSyncing")
        else:
            mylogger.debug(f"{_from} to {_to}", label="rSyncing")
            proc = subprocess.call(['rsync', '-a', '-m', _from, _to])
            return proc
Esempio n. 2
0
def txt(src_dir, output_path=None):
    mylogger.info(f"Processing {src_dir}")
    hub = Writhub(mode='txt', src_dir=src_dir, output_path=output_path)

    mylogger.info(f"Found {len(hub.content_list)} files")
    for i, p in enumerate(hub.content_list):
        mylogger.debug(f"{i}: {p}")

    hub.publish()
    mylogger.info(f"Publishing to {hub.target_dir}")
    mylogger.info(f"Collated file is at: {hub.target_path}")
Esempio n. 3
0
    def get_content_list(srcdir:Path, mode:str) -> tList[Path]:
        """returns a list of alphabetically sorted source files that meet selection criteria"""
        mypaths = []
        for path in srcdir.glob(f"*.{mode}"):
            if any(re.match(rx, path.name) for rx in IGNORE_FILE_PATTERNS):
                mylogger.debug(f'{path} based on `IGNORE_FILE_PATTERNS`',  label="Ignoring")
            elif any(re.match(rx, path.parent.name) for rx in IGNORE_DIR_PATTERNS):
            # TODO: right now, only the parent directory is checked for ignored dir patterns
                mylogger.debug(f'{path} based on `IGNORE_DIR_PATTERNS`',  label="Ignoring")
            else:
                mypaths.append(path)

        # TODO: decide whether to sort by
        return sorted(mypaths)
Esempio n. 4
0
def foo():
    """
    foo this is for foos!
    """
    mylogger.info("Welcome to writhub – a test")
    mylogger.info('compile header:', WRITHUB_PROJECT_HEADER)
    mylogger.debug("A debug message")
    mylogger.info("Info for you")
    mylogger.warning("Warning for this")
    mylogger.critical("Critical oops")
    mylogger.error("An error appears!")

    def _fubar(txt: str) -> int:
        val = len(str(txt))
        print("You gave me", txt, 'but i give you', val)
        return val

    _fubar(9)
Esempio n. 5
0
    def self_check(self:Writhub):
        """self file check"""
        mylogger.debug(f"src_dir: {self.src_dir}")
        mylogger.debug(f"target_dir: {self.target_dir}")
        mylogger.debug(f"target_path: {self.target_path}")

        pass
Esempio n. 6
0
def md(src_dir, output_path=None):
    """
    Convert a SRC_DIR directory of *.md files into one big Markdown file

    Example:

        $ writhub md examples/post
    """

    # TK: this is just debug info/ remove gather_markdown_paths
    mylogger.info(f"Processing {src_dir}")
    hub = Writhub(mode='md', src_dir=src_dir, output_path=output_path)

    mylogger.info(f"Found {len(hub.content_list)} files")
    for i, p in enumerate(hub.content_list):
        mylogger.debug(f"{i}: {p}")


#   collate_markdown_to_file(src_dir, target_path, ignore_output_filename=output_filename)
    mylogger.info(f"Publishing to {hub.target_dir}")
    hub.publish()
    mylogger.info(f"Collated file is at: {hub.target_path}")