Example #1
0
import os

from os.path import join
from fnmatch import fnmatch

from acrylamid import log, commands
from acrylamid.tasks import task, argument
from acrylamid.helpers import event

tracked = set([])

arguments = [
    argument(
        "-f",
        "--force",
        action="store_true",
        dest="force",
        help="remove all files generated by Acrylamid",
        default=False,
    ),
    argument(
        "-n", "--dry-run", dest="dryrun", action="store_true", help="show what would have been deleted", default=False
    ),
]


def track(path, **kw):
    global tracked
    tracked.add(path)


def excluded(conf, root, path, excl_files):
Example #2
0
if PY2K:
    from urlparse import urlparse
    import xmlrpclib as xmlrpc
    setattr(xmlrpc, 'client', xmlrpc)
else:
    from urllib.parse import urlparse
    import xmlrpc.client

try:
    import twitter
except ImportError:
    twitter = None  # NOQA

arguments = [
    argument("service", nargs="?", type=str, choices=["twitter", "back"],
        default="back", help="ping service (default: back)"),

    argument("-a", "--all", dest="all", action="store_true", default=False,
        help="ping all entries (default: only the newest)"),
    argument("-p", dest="file", type=str, default=None, help="ping specific article"),

    argument("-n", "--dry-run", dest="dryrun", action='store_true',
             help="show what would have been pingbacked", default=False),
    argument("-j", "--jobs", dest="jobs", type=int, default=10, help="N parallel requests"),
] + [option(i) for i in range(10)]


def pingback(src, dest, dryrun=False):
    """Makes a pingback request to dest on behalf of src, i.e. effectively
    saying to dest that "the page at src is linking to you"."""
Example #3
0

def run(conf, env, options):
    """Subcommand: check -- run W3C over generated output and check destination
    of linked items"""

    paths = [path for path in utils.filelist(conf['output_dir']) if path.endswith('.html')]

    if options.random:
        random.shuffle(paths)

    if options.links:
        validate(paths, options.jobs)
    else:
        w3c(paths, conf, warn=options.warn, sleep=options.sleep)


arguments = [
    argument("-r", "--random", dest="random", action="store_true", default=False,
        help="random order"),
    argument("-s", type=float, default=0.2, dest="sleep",
        help="seconds between requests (default 0.2)"),
    argument("-w", action="store_true", default=False, dest="warn",
        help="show W3C warnings"),
    argument("-l", "--links", action="store_true", default=False, dest="links",
        help="validate links"),
    argument("-j", "--jobs", dest="jobs", type=int, default=10, help="N parallel requests"),
]

register(['check'], arguments, "run W3C or validate links", func=run)
Example #4
0
import re
from urlparse import urlparse

from acrylamid.tasks import task, argument

from acrylamid.utils import filelist
from acrylamid.errors import AcrylamidException
from acrylamid.readers import Entry
from acrylamid.helpers import memoize, joinurl
from acrylamid.commands import initialize

from acrylamid.lib.requests import head, URLError, HTTPError

arguments = [
    argument("-", "--all", dest="all", action="store_true", default=False,
        help="ping all entries (default: only new)"),
]


def pingback(src, dest):
    """Makes a pingback request to dest on behalf of src, i.e. effectively
    saying to dest that "the page at src is linking to you"."""

    def search_link(content):
        match = re.search(r'<link rel="pingback" href="([^"]+)" ?/?>', content)
        return match and match.group(1)

    request_url = 'http:%s' % dest if dest.startswith('//') else dest

    try:
        info = head(request_url).info()
Example #5
0
if PY2K:
    from urllib2 import urlopen, Request, HTTPError
    from urlparse import urlsplit
else:
    from urllib.request import urlopen, Request
    from urllib.error import HTTPError
    from urllib.parse import urlsplit

try:
    input = raw_input
except NameError:
    pass

arguments = [
    argument("src", metavar="FILE|URL"),
    argument("-f",
             "--force",
             dest="force",
             action="store_true",
             help="overwrite existing entries",
             default=False),
    argument("-m",
             dest="fmt",
             default="Markdown",
             help="reconvert HTML to FMT"),
    argument("-k",
             "--keep-links",
             dest="keep",
             action="store_true",
             help="keep permanent links",
Example #6
0
from acrylamid import readers, helpers, compat
from acrylamid.tasks import task, argument
from acrylamid.colors import green, yellow, red, blue, white

from acrylamid.lib. async import Threadpool
from acrylamid.lib.requests import get, head, HTTPError, URLError

if compat.PY2K:
    from urllib import quote
else:
    from urllib.parse import quote

arguments = [
    argument("action",
             nargs="?",
             choices=["W3C", "links"],
             default="W3C",
             help="check action (default: W3C compatibility)"),
    argument("-r",
             "--random",
             dest="random",
             action="store_true",
             default=False,
             help="random order"),
    argument("-s",
             type=float,
             default=0.2,
             dest="sleep",
             help="seconds between requests (default 0.2)"),
    argument("-w",
             action="store_true",
Example #7
0
if PY2K:
    from urllib2 import urlopen, Request, HTTPError
    from urlparse import urlsplit
else:
    from urllib.request import urlopen, Request
    from urllib.error import HTTPError
    from urllib.parse import urlsplit

try:
    input = raw_input
except NameError:
    pass

arguments = [
    argument("src", metavar="FILE|URL"),
    argument("-f", "--force", dest="force", action="store_true",
        help="overwrite existing entries", default=False),
    argument("-m", dest="fmt", default="Markdown",
        help="reconvert HTML to FMT"),
    argument("-k", "--keep-links", dest="keep", action="store_true",
        help="keep permanent links", default=False),
    argument("-p", "--pandoc", dest="pandoc", action="store_true",
        help="use pandoc first", default=False),
    argument("-a", dest="args", nargs="+", action="store", metavar="ARG",
        type=str, help="add argument to header section", default=[]),
]

if sys.version_info < (2, 7):
    setattr(ElementTree, 'ParseError', ExpatError)
Example #8
0
# License: BSD Style, 2 clauses. see acrylamid/__init__.py

import os

from os.path import join

from acrylamid import log, commands, readers
from acrylamid.tasks import task, argument
from acrylamid.helpers import event

tracked = set([])

arguments = [
    argument("-f",
             "--force",
             action="store_true",
             dest="force",
             help="remove all files generated by Acrylamid",
             default=False),
    argument("-n",
             "--dry-run",
             dest="dryrun",
             action='store_true',
             help="show what would have been deleted",
             default=False)
]


def track(path, **kw):
    global tracked
    tracked.add(path)
Example #9
0
import sys
import os
import io
import imp
import shutil
import string

from os.path import exists, isfile, isdir, join, dirname, basename

from acrylamid import log, defaults
from acrylamid import AcrylamidException
from acrylamid.tasks import task, argument
from acrylamid.helpers import event

arguments = [
    argument("dest", metavar="DEST|FILE", nargs="?", default="."),
    argument("-f", "--force", action="store_true", dest="overwrite",
        help="don't ask, just overwrite", default=False),
    argument("--theme", dest="theme", default="html5",
        help="use theme (minimalistic HTML5 per default)"),
    argument("--mako", action="store_const", dest="engine", const="mako",
        help="use the Mako template engine", default=""),
    argument("--jinja2", action="store_const", dest="engine", const="jinja2",
        help="use the Jinja2 template engine")
]


def resolve(options, theme, files):
    """Takes a files dictionary and yields src and full destination path.

    :param options: Argparse namespace object
Example #10
0
from acrylamid import log, readers, commands
from acrylamid.errors import AcrylamidException

from acrylamid.tasks import task, argument
from acrylamid.utils import force_unicode as u
from acrylamid.helpers import safe, event

yaml, rst, md = \
    lambda title, date: u"---\ntitle: %s\ndate: %s\n---\n\n" % (safe(title), date), \
    lambda title, date: u"%s\n" % title + "="*len(title) + '\n\n' + ":date: %s\n\n" % date, \
    lambda title, date: u"Title: %s\nDate: %s\n\n" % (title, date)

formats = {'.md': md, '.mkdown': md, '.rst': rst, '.rest': rst}


@task('new', [argument("title", nargs="*", default=None)], help="create a new entry")
def run(conf, env, options):
    """Subcommand: new -- create a new blog entry the easy way.  Either run
    ``acrylamid new My fresh new Entry`` or interactively via ``acrylamid new``
    and the file will be created using the preferred permalink format."""

    # we need the actual default values
    commands.initialize(conf, env)

    ext = conf.get('content_extension', '.txt')
    fd, tmp = tempfile.mkstemp(suffix=ext, dir='.cache/')

    editor = os.getenv('VISUAL') if os.getenv('VISUAL') else os.getenv('EDITOR')
    tt = formats.get(ext, yaml)

    if options.title:
Example #11
0
# -*- encoding: utf-8 -*-
#
# Copyright 2012 posativ <*****@*****.**>. All rights reserved.
# License: BSD Style, 2 clauses. see acrylamid/__init__.py

import sys
import os
import argparse
import subprocess

from acrylamid import log
from acrylamid.tasks import argument, task
from acrylamid.errors import AcrylamidException

arguments = [argument("task", nargs="?"), argument("args", nargs=argparse.REMAINDER)]


@task(['deploy', 'dp'], arguments, help="run task")
def run(conf, env, options):
    """Subcommand: deploy -- run the shell command specified in
    DEPLOYMENT[task] using Popen. Each string value from :doc:`conf.py` is
    added to the execution environment. Every argument after ``acrylamid
    deploy task ARG1 ARG2`` is appended to cmd."""

    if options.task is None:
        for task in conf.get('deployment', {}).keys():
            print >>sys.stdout, task
        sys.exit(0)

    task, args = options.task, options.args
    cmd = conf.get('deployment', {}).get(task, None)
Example #12
0
# License: BSD Style, 2 clauses -- see LICENSE.

from __future__ import print_function

import sys
import os
import argparse
import subprocess

from acrylamid import log
from acrylamid.tasks import argument, task
from acrylamid.errors import AcrylamidException
from acrylamid.compat import iterkeys, iteritems, string_types, PY2K

arguments = [
    argument("task", nargs="?"),
    argument("args", nargs=argparse.REMAINDER),
    argument("--list",
             dest="list",
             action="store_true",
             default=False,
             help="list available tasks")
]


@task(['deploy', 'dp'], arguments, help="run task")
def run(conf, env, options):
    """Subcommand: deploy -- run the shell command specified in
    DEPLOYMENT[task] using Popen. Each string value from :doc:`conf.py` is
    added to the execution environment. Every argument after ``acrylamid
    deploy task ARG1 ARG2`` is appended to cmd."""
Example #13
0
# License: BSD Style, 2 clauses. see acrylamid/__init__.py

from __future__ import unicode_literals

import sys
import os
import io
import shutil

from os.path import exists, isfile, isdir, join, dirname, basename

from acrylamid import log, defaults
from acrylamid.tasks import task, argument

arguments = [
    argument("dest", metavar="DEST|FILE", nargs="?", default="."),
    argument("-f",
             "--force",
             action="store_true",
             dest="overwrite",
             help="don't ask, just overwrite",
             default=False),
    argument("--xhtml",
             action="store_const",
             dest="theme",
             const="xhtml",
             help="use XHTML theme",
             default="html5"),
    argument("--html5",
             action="store_const",
             dest="theme",
Example #14
0
from acrylamid import readers, commands
from acrylamid.core import cache
from acrylamid.tasks import task, argument
from acrylamid.colors import white, blue, green


class Gitlike(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):

        namespace.max = 10 * namespace.max + int(option_string.strip('-'))


option = lambda i: argument('-%i' % i,
                            action=Gitlike,
                            help=argparse.SUPPRESS,
                            nargs=0,
                            dest="max",
                            default=0)
arguments = [option(i) for i in range(10)]


def ago(date, now=datetime.datetime.now()):

    delta = now - date

    secs = delta.seconds
    days = delta.days

    if days == 0:
        if secs < 10:
            return "just now"
Example #15
0
import time
import random
import collections

from urllib import quote
from xml.sax.saxutils import unescape

from acrylamid import readers, helpers
from acrylamid.tasks import task, argument
from acrylamid.colors import green, yellow, red, blue, white

from acrylamid.lib.async import Threadpool
from acrylamid.lib.requests import get, head, HTTPError, URLError

arguments = [
    argument("action", nargs="?", choices=["W3C", "links"], default="W3C",
        help="check action (default: W3C compatibility)"),
    argument("-r", "--random", dest="random", action="store_true", default=False,
        help="random order"),
    argument("-s", type=float, default=0.2, dest="sleep",
        help="seconds between requests (default 0.2)"),
    argument("-w", action="store_true", default=False, dest="warn",
        help="show W3C warnings"),
    argument("-j", "--jobs", dest="jobs", type=int, default=10, help="N parallel requests"),
]


def w3c(paths, conf, warn=False, sleep=0.2):
    """Validate HTML by using the validator.w3.org API.

    :param paths: a list of HTML files we map to our actual domain
    :param conf: configuration
Example #16
0
# -*- encoding: utf-8 -*-
#
# Copyright 2012 posativ <*****@*****.**>. All rights reserved.
# License: BSD Style, 2 clauses. see acrylamid/__init__.py

import sys
import os
import argparse
import subprocess

from acrylamid import log
from acrylamid.tasks import argument, task
from acrylamid.errors import AcrylamidException

arguments = [
    argument("task", nargs="?"),
    argument("args", nargs=argparse.REMAINDER)
]


@task(['deploy', 'dp'], arguments, help="run task")
def run(conf, env, options):
    """Subcommand: deploy -- run the shell command specified in
    DEPLOYMENT[task] using Popen. Each string value from :doc:`conf.py` is
    added to the execution environment. Every argument after ``acrylamid
    deploy task ARG1 ARG2`` is appended to cmd."""

    if options.task is None:
        for task in conf.get('deployment', {}).keys():
            print >> sys.stdout, task
        sys.exit(0)
Example #17
0
from acrylamid import readers, commands
from acrylamid.core import cache
from acrylamid.utils import batch
from acrylamid.tasks import task, argument
from acrylamid.colors import white, blue, green, normal
from acrylamid.views.tag import fetch


class Gitlike(argparse.Action):

    def __call__(self, parser, namespace, values, option_string=None):

        namespace.max = 10 * namespace.max + int(option_string.strip('-'))


option = lambda i: argument('-%i' % i, action=Gitlike, help=argparse.SUPPRESS,
    nargs=0, dest="max", default=0)
arguments = [
    argument("type", nargs="?", type=str, choices=["summary", "tags"],
        default="summary", help="info about given type (default: summary)"),
    argument("--coverage", type=int, default=None, dest="coverage",
        metavar="N", help="discover posts with uncommon tags")
] + [option(i) for i in range(10)]


def ago(date, now=datetime.datetime.now()):

    delta = now - date

    secs = delta.seconds
    days = delta.days
Example #18
0
    from urlparse import urlparse
    import xmlrpclib as xmlrpc
    setattr(xmlrpc, 'client', xmlrpc)
else:
    from urllib.parse import urlparse
    import xmlrpc.client

try:
    import twitter
except ImportError:
    twitter = None  # NOQA

arguments = [
    argument("service",
             nargs="?",
             type=str,
             choices=["twitter", "back"],
             default="back",
             help="ping service (default: back)"),
    argument("-a",
             "--all",
             dest="all",
             action="store_true",
             default=False,
             help="ping all entries (default: only the newest)"),
    argument("-p",
             dest="file",
             type=str,
             default=None,
             help="ping specific article"),
    argument("-n",
             "--dry-run",
Example #19
0
# -*- encoding: utf-8 -*-
#
# Copyright 2012 Martin Zimmermann <*****@*****.**>. All rights reserved.
# License: BSD Style, 2 clauses -- see LICENSE.

import sys
import os
import argparse
import subprocess

from acrylamid import log
from acrylamid.tasks import argument, task
from acrylamid.errors import AcrylamidException

arguments = [
    argument("task", nargs="?"),
    argument("args", nargs=argparse.REMAINDER),
    argument("--list", dest="list", action="store_true", default=False,
        help="list available tasks")
]


@task(['deploy', 'dp'], arguments, help="run task")
def run(conf, env, options):
    """Subcommand: deploy -- run the shell command specified in
    DEPLOYMENT[task] using Popen. Each string value from :doc:`conf.py` is
    added to the execution environment. Every argument after ``acrylamid
    deploy task ARG1 ARG2`` is appended to cmd."""

    if options.list:
        for task in conf.get('deployment', {}).keys():
Example #20
0
from os.path import join, getmtime

from acrylamid import utils
from acrylamid.core import cache
from acrylamid.tasks import task, argument
from acrylamid.colors import white, blue, green
from acrylamid.readers import Entry


class Gitlike(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):

        namespace.max = 10 * namespace.max + int(option_string.strip("-"))


option = lambda i: argument("-%i" % i, action=Gitlike, help=argparse.SUPPRESS, nargs=0, dest="max", default=0)
arguments = [option(i) for i in range(10)]


def ago(date, now=datetime.datetime.now()):

    delta = now - date

    secs = delta.seconds
    days = delta.days

    if days == 0:
        if secs < 10:
            return "just now"
        if secs < 60:
            return str(secs) + " seconds ago"
Example #21
0
from acrylamid.helpers import safe, event

try:
    input = raw_input
except NameError:
    pass

yaml, rst, md = \
    lambda title, date: u"---\ntitle: %s\ndate: %s\n---\n\n" % (safe(title), date), \
    lambda title, date: u"%s\n" % title + "="*len(title) + '\n\n' + ":date: %s\n\n" % date, \
    lambda title, date: u"Title: %s\nDate: %s\n\n" % (title, date)

formats = {'.md': md, '.mkdown': md, '.rst': rst, '.rest': rst}


@task('new', [argument("title", nargs="*", default=None)],
      help="create a new entry")
def run(conf, env, options):
    """Subcommand: new -- create a new blog entry the easy way.  Either run
    ``acrylamid new My fresh new Entry`` or interactively via ``acrylamid new``
    and the file will be created using the preferred permalink format."""

    # we need the actual default values
    commands.initialize(conf, env)

    # config content_extension originally defined as string, not a list
    extlist = conf.get('content_extension', ['.txt'])
    if isinstance(extlist, string_types):
        ext = extlist
    else:
        ext = extlist[0]
Example #22
0
if PY2K:
    from itertools import izip_longest as izip
else:
    from itertools import zip_longest as izip


class Gitlike(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):

        namespace.max = 10 * namespace.max + int(option_string.strip('-'))


option = lambda i: argument('-%i' % i,
                            action=Gitlike,
                            help=argparse.SUPPRESS,
                            nargs=0,
                            dest="max",
                            default=0)
arguments = [
    argument("type",
             nargs="?",
             type=str,
             choices=["summary", "tags"],
             default="summary",
             help="info about given type (default: summary)"),
    argument("--coverage",
             type=int,
             default=None,
             dest="coverage",
             metavar="N",
             help="discover posts with uncommon tags")