Exemplo n.º 1
0
    def __init__(self):
        self.verbose = False
        config_path = os.path.join(CONFIG_DIR, "blog_config.cfg")
        self.config = Config(config_path, backup_dir=BACKUP_DIR)
        self.blog_list = self.config.read(all_keys=True)
        self.config_keys = [
            "google_analytics_id",
            "disqus_username",
            "blog_images_dir",
            "templates_dir",
            "blog_posts_dir",
            "default",
            "working_dir",
            "blog_dir",
        ]
        self.optional_config = [
            "meta_format",  # comment format in metadata
            "post_extract_list",  # resource to extract from file
            "index_div_name",  # div name of posts list in blog index
            "filter_post_without_title",  # filter titleless post from indexing
            "working_dir_timestamp",  # Timestamp of last checked working dir
            "create_nbdata_file",  # Flag for creating nbdata file
            "delete_ipynb_meta",  # Delete metadata in ipynb file after reading
            "feed_file",  # Path of feed file
            "site_url",  # URL of website [for building feed links].
            "md_summary_limit",  # No of charectar to include in md summary.
            "ipynb_summary_limit",  # ipynb char limit or Cell no to extract
        ]

        self.SUPPORTED_EXTENSIONS = ["md", "ipynb", "html"]
        self.current_blog = ""
Exemplo n.º 2
0
    def __init__(self):
        self.verbose = False
        config_path = os.path.join(CONFIG_DIR, 'blog_config.cfg')
        self.config = Config(config_path, backup_dir='~/.blogger/backup/')
        self.blog_list = self.config.read(all_keys=True)
        self.config_keys = [
            'google_analytics_id', 'disqus_username', 'blog_images_dir',
            'templates_dir', 'blog_posts_dir', 'default', 'working_dir',
            'blog_dir'
        ]
        self.optional_config = [
            'meta_format', 'post_extract_list', 'index_div_name',
            'filter_post_without_title', 'working_dir_timestamp',
            'create_nbdata_file', 'delete_ipynb_meta'
        ]

        self.SUPPORTED_EXTENSIONS = ['md', 'ipynb', 'html']
        self.current_blog = ''
Exemplo n.º 3
0
class Context(object):
    def __init__(self):
        self.verbose = False
        config_path = os.path.join(CONFIG_DIR, 'blog_config.cfg')
        self.config = Config(config_path, backup_dir='~/.blogger/backup/')
        self.blog_list = self.config.read(all_keys=True)
        self.config_keys = [
            'google_analytics_id', 'disqus_username', 'blog_images_dir',
            'templates_dir', 'blog_posts_dir', 'default', 'working_dir',
            'blog_dir'
        ]
        self.optional_config = [
            'meta_format', 'post_extract_list', 'index_div_name',
            'filter_post_without_title', 'working_dir_timestamp',
            'create_nbdata_file', 'delete_ipynb_meta'
        ]

        self.SUPPORTED_EXTENSIONS = ['md', 'ipynb', 'html']
        self.current_blog = ''

    def log(self, msg, *args):
        """Logs a message to stderr."""
        if args:
            for arg in args:
                msg += ' ' + str(arg)
        click.echo(msg, file=sys.stderr)

    def vlog(self, msg, *args):
        """Logs a message to stderr only if verbose is enabled."""
        if self.verbose:
            self.log(msg, *args)

    def blog_exists(self, blog):
        return False if not self.config.read(key=blog) else True

    @property
    def default_blog(self):
        cfg = self.config.get_dict()
        for i in cfg:
            if 'default' in cfg[i]:
                return i
Exemplo n.º 4
0
class Context(object):
    def __init__(self):
        self.verbose = False
        config_path = os.path.join(CONFIG_DIR, "blog_config.cfg")
        self.config = Config(config_path, backup_dir=BACKUP_DIR)
        self.blog_list = self.config.read(all_keys=True)
        self.config_keys = [
            "google_analytics_id",
            "disqus_username",
            "blog_images_dir",
            "templates_dir",
            "blog_posts_dir",
            "default",
            "working_dir",
            "blog_dir",
        ]
        self.optional_config = [
            "meta_format",  # comment format in metadata
            "post_extract_list",  # resource to extract from file
            "index_div_name",  # div name of posts list in blog index
            "filter_post_without_title",  # filter titleless post from indexing
            "working_dir_timestamp",  # Timestamp of last checked working dir
            "create_nbdata_file",  # Flag for creating nbdata file
            "delete_ipynb_meta",  # Delete metadata in ipynb file after reading
            "feed_file",  # Path of feed file
            "site_url",  # URL of website [for building feed links].
            "md_summary_limit",  # No of charectar to include in md summary.
            "ipynb_summary_limit",  # ipynb char limit or Cell no to extract
        ]

        self.SUPPORTED_EXTENSIONS = ["md", "ipynb", "html"]
        self.current_blog = ""

    def log(self, msg, *args):
        """Logs a message to stderr."""
        msg = str(msg)
        if args:
            for arg in args:
                msg += " " + str(arg)

        message = msg.lower() if msg else ""

        # handle basic coloring
        if "error" in message:
            click.secho(msg, file=sys.stderr, bold=True, blink=False, fg="bright_red")
        elif "warning" in message or "!" in message:
            click.secho(msg, file=sys.stderr, bold=True, fg="bright_yellow")
        elif "converting" in message or "adding" in message:
            click.secho(msg, file=sys.stderr, fg="blue")
        elif "finished" in message or "done" in message or "successfully" in message:
            click.secho(msg, file=sys.stderr, fg="green")

        else:
            click.echo(msg, file=sys.stderr)

    def vlog(self, msg, *args):
        """Logs a message to stderr only if verbose is enabled."""
        if self.verbose:
            self.log(msg, *args)

    def blog_exists(self, blog):
        return False if not self.config.read(key=blog) else True

    @property
    def default_blog(self):
        cfg = self.config.get_dict()
        for i in cfg:
            if "default" in cfg[i]:
                return i
Exemplo n.º 5
0
def get_config(ctx):
    config_path = os.path.join(CONFIG_DIR, ctx.current_blog, "meta.json")
    config = Config(config_path)
    return config