コード例 #1
0
ファイル: commands.py プロジェクト: MeirKriheli/acrylamid
def new(conf, env, title, prompt=True):
    """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 defaults values
    initialize(conf, env)

    fd, tmp = tempfile.mkstemp(suffix='.txt', dir='.cache/')
    editor = os.getenv('VISUAL') if os.getenv('VISUAL') else os.getenv('EDITOR')

    if not title:
        title = raw_input("Entry's title: ")
    title = escape(title)

    with io.open(fd, 'w') as f:
        f.write(u'---\n')
        f.write(u'title: %s\n' % title)
        f.write(u'date: %s\n' % datetime.now().strftime(conf['date_format']))
        f.write(u'---\n\n')

    entry = readers.Entry(tmp, conf)
    p = join(conf['content_dir'], dirname(entry.permalink)[1:])

    try:
        os.makedirs(p.rsplit('/', 1)[0])
    except OSError:
        pass

    filepath = p + '.txt'
    if isfile(filepath):
        raise AcrylamidException('Entry already exists %r' % filepath)
    shutil.move(tmp, filepath)
    event.create(filepath)

    if datetime.now().hour == 23 and datetime.now().minute > 45:
        log.info("notice  consider editing entry.date-day after you passed mignight!")

    if not prompt:
        return

    try:
        if editor:
            retcode = subprocess.call([editor, filepath])
        elif sys.platform == 'darwin':
            retcode = subprocess.call(['open', filepath])
        else:
            retcode = subprocess.call(['xdg-open', filepath])
    except OSError:
        raise AcrylamidException('Could not launch an editor')

    # XXX process detaches... m(
    if retcode < 0:
        raise AcrylamidException('Child was terminated by signal %i' % -retcode)

    if os.stat(filepath)[6] == 0:
        raise AcrylamidException('File is empty!')
コード例 #2
0
ファイル: test_entry.py プロジェクト: sebix/acrylamid
def create(path, **kwargs):

    with open(path, 'w') as fp:
        fp.write('---\n')
        for k, v in kwargs.iteritems():
            if isinstance(v, basestring):
                v = escape(v)
            fp.write('%s: %s\n' % (k, v))
        fp.write('---\n')
コード例 #3
0
ファイル: importer.py プロジェクト: MeirKriheli/acrylamid
    def create(defaults, title, date, author, content, fmt, permalink=None, tags=None):

        global USED_WORDPRESS

        fd, tmp = tempfile.mkstemp(suffix='.txt')
        title = escape(title)

        with io.open(fd, 'w') as f:
            f.write(u'---\n')
            f.write(u'title: %s\n' % title)
            if author != defaults.get('author', None):
                f.write(u'author: %s\n' % author)
            f.write(u'date: %s\n' % date.strftime(conf['date_format']))
            f.write(u'filter: [%s, ]\n' % fmt)
            if tags:
                f.write(u'tags: [%s]\n' % ', '.join(tags))
            if permalink:
                f.write(u'permalink: %s\n' % permalink)
            for arg in options.args:
                f.write(arg.strip() + u'\n')
            f.write(u'---\n\n')

            # this are fixes for WordPress because they don't save HTML but a
            # stupid mixed-in form of HTML making it very difficult to get either HTML
            # or reStructuredText/Markdown
            if USED_WORDPRESS and fmt == 'markdown':
                content = content.replace("\n ", "  \n")
            elif USED_WORDPRESS and fmt == 'rst':
                content = content.replace('\n ', '\n\n')
            f.write(content+u'\n')

        entry = Entry(tmp, conf)
        p = join(conf['content_dir'], dirname(entry.permalink)[1:])

        try:
            os.makedirs(p.rsplit('/', 1)[0])
        except OSError:
            pass

        filepath = p + '.txt'
        if isfile(filepath) and not options.force:
            raise AcrylamidException('Entry already exists %r' % filepath)
        shutil.move(tmp, filepath)
        event.create(filepath)
コード例 #4
0
ファイル: test_helpers.py プロジェクト: MagicSword/acrylamid
    def test_escape(self):

        assert helpers.escape('Hello World') == 'Hello World'
        assert helpers.escape('Hello: World') == '"Hello: World"'
        assert helpers.escape('Hello\'s World') == '"Hello\'s World"'
        assert helpers.escape('Hello "World"') == "'Hello \"World\"'"
コード例 #5
0
ファイル: test_utils.py プロジェクト: sebix/acrylamid
    def test_escape(self):

        self.assertEqual(helpers.escape('Hello World'), 'Hello World')
        self.assertEqual(helpers.escape('Hello: World'), '"Hello: World"')
        self.assertEqual(helpers.escape('Hello\'s World'), '"Hello\'s World"')
        self.assertEqual(helpers.escape('Hello "World"'), "'Hello \"World\"'")