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 defaults 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((conf.get('metastyle') == 'native', ext), yaml) if not options.title: options.title = raw_input("Entry's title: ") title = (' '.join(options.title)) if not PY3: title = title.decode('utf-8') with io.open(fd, 'w') as f: f.write(tt(title, datetime.now().strftime(conf['date_format']))) 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 + ext 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 log.level() >= log.WARN: 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!')
def run(conf, env, options): """Subcommand: info -- a short overview of a blog.""" commands.initialize(conf, env) if options.type == "summary": do_summary(conf, env, options) elif options.type == "tags": do_tags(conf, env, options)
def run(conf, env, options): """Subcommand: ping -- notify external ressources via Pingback etc.""" initialize(conf, env) # we access the cache, so we must initialize first entrylist = sorted([Entry(e, conf) for e in filelist(conf['content_dir'], conf.get('entries_ignore', []))], key=lambda k: k.date, reverse=True) entrylist = [entry for entry in entrylist if not entry.draft] print joinurl(conf['www_root'], entrylist[0].permalink) links = re.findall('https?://[^ ]+', entrylist[0].source) print links
def run(conf, env, options): """Subcommand: ping -- notify external resources via Pingback etc.""" commands.initialize(conf, env) entrylist = [entry for entry in readers.load(conf)[0] if not entry.draft] if options.file: try: entrylist = [ filter(lambda e: e.filename == options.file, entrylist)[0] ] except IndexError: raise AcrylamidException("no such post!") if options.service == 'twitter': if twitter is None: raise AcrylamidException("'twitter' egg not found") for entry in entrylist if options.all else entrylist[:options. max or 1]: tweet(entry, conf, options.dryrun) return # XXX we should search for actual hrefs not random grepping, but this # requires access to the cache at non-runtime which is unfortunately # not possible yet. patterns = [ r'(?<=\n)\[.*?\]:\s?(https?://.+)$', # referenced markdown r'\[[^\]]+\]\((https?://[^\)]+)\)', # inline markdown r'(?<=\n)\.\.\s+[^:]+:\s+(https?://.+)$', # referenced docutils r'`[^<]+ <(https?://[^>]+)>`_', # inline docutils ] pool = Threadpool(options.jobs) ping = lambda src, dest: pingback(helpers.joinurl(conf['www_root'], src), dest, options.dryrun) for entry in entrylist if options.all else entrylist[:options.max or 1]: for href in sum( [re.findall(pat, entry.source, re.M) for pat in patterns], []): pool.add_task(ping, *[entry.permalink, href]) try: pool.wait_completion() except KeyboardInterrupt: sys.exit(1)
def run(conf, env, options): """Subcommand: ping -- notify external resources via Pingback etc.""" commands.initialize(conf, env) entrylist = [entry for entry in readers.load(conf)[0] if not entry.draft] if options.file: try: entrylist = [filter(lambda e: e.filename == options.file, entrylist)[0]] except IndexError: raise AcrylamidException("no such post!") if options.service == 'twitter': if twitter is None: raise AcrylamidException("'twitter' egg not found") for entry in entrylist if options.all else entrylist[:options.max or 1]: tweet(entry, conf, options.dryrun) return # XXX we should search for actual hrefs not random grepping, but this # requires access to the cache at non-runtime which is unfortunately # not possible yet. patterns = [ r'(?<=\n)\[.*?\]:\s?(https?://.+)$', # referenced markdown r'\[[^\]]+\]\((https?://[^\)]+)\)', # inline markdown r'(?<=\n)\.\.\s+[^:]+:\s+(https?://.+)$', # referenced docutils r'`[^<]+ <(https?://[^>]+)>`_', # inline docutils ] pool = Threadpool(options.jobs) ping = lambda src, dest: pingback(helpers.joinurl(conf['www_root'], src), dest, options.dryrun) for entry in entrylist if options.all else entrylist[:options.max or 1]: for href in sum([re.findall(pat, entry.source, re.M) for pat in patterns], []): pool.add_task(ping, *[entry.permalink, href]) try: pool.wait_completion() except KeyboardInterrupt: sys.exit(1)
def run(conf, env, options): """Subcommand: import -- import entries and settings from an existing RSS/Atom feed or WordPress dump. ``acrylamid import http://example.com/feed/`` or any local FILE is fine. By default we use ``html2text`` (if available) to re-convert to Markdown, with ``-m rst`` you can also re-convert to reST if you have ``html2rest`` installed. As fallback there we have ``pandoc`` but you can use pandoc as first choice with the ``-p`` flag. If you don't like any reconversion, simply use ``-m html``. This command supports the force flag to override already existing files. Use with care!""" # we need the actual defaults values for permalink format commands.initialize(conf, env) content = fetch(options.src, auth=options.__dict__.get('auth', None)) defaults, items = parse(content) build(conf, env, defaults, items, options)
def run(conf, env, options): """Subcommand: info -- a short overview of a blog.""" limit = options.max if options.max > 0 else 5 commands.initialize(conf, env) entrylist, pages = readers.load(conf) print print "acrylamid", blue(env["version"]) + ",", print "cache size:", blue("%0.2f" % (cache.size / 1024.0 ** 2)) + " mb" print for entry in entrylist[:limit]: print " ", green(ago(entry.date.replace(tzinfo=None)).ljust(13)), print white(entry.title) if entry.draft else normal(entry.title) print print "%s published," % blue(len([e for e in entrylist if not e.draft])), print "%s drafted articles" % blue(len([e for e in entrylist if e.draft])) time = localtime(getmtime(join(conf.get("cache_dir", ".cache/"), "info"))) print "last compilation at %s" % blue(strftime("%d. %B %Y, %H:%M", time))
def run(conf, env, options): """Subcommand: info -- a short overview of a blog.""" limit = options.max if options.max > 0 else 5 commands.initialize(conf, env) entrylist, pages = readers.load(conf) print print 'acrylamid', blue(env['version']) + ',', print 'cache size:', blue('%0.2f' % (cache.size / 1024.0**2)) + ' mb' print for entry in entrylist[:limit]: print ' ', green(ago(entry.date.replace(tzinfo=None)).ljust(13)), print white(entry.title) if entry.draft else entry.title print print '%s published,' % blue(len([e for e in entrylist if not e.draft])), print '%s drafted articles' % blue(len([e for e in entrylist if e.draft])) time = localtime(getmtime(join(conf.get('cache_dir', '.cache/'), 'info'))) print 'last compilation at %s' % blue(strftime('%d. %B %Y, %H:%M', time))
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] 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: title = u(' '.join(options.title)) else: title = u(input("Entry's title: ")) with io.open(fd, 'w', encoding='utf-8') as f: f.write(tt(title, datetime.now().strftime(conf['date_format']))) entry = readers.Entry(tmp, conf) p = join(conf['content_dir'], splitext(entry.permalink.strip('/'))[0]) try: os.makedirs(p.rsplit('/', 1)[0]) except OSError: pass filepath = p + ext if isfile(filepath): raise AcrylamidException('Entry already exists %r' % filepath) shutil.move(tmp, filepath) event.create('new', filepath) if datetime.now().hour == 23 and datetime.now().minute > 45: log.info( "notice don't forget to update entry.date-day after mignight!") if log.level() >= log.WARN: return try: if editor: retcode = subprocess.call(shlex.split(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!')
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] 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: title = u(' '.join(options.title)) else: title = u(input("Entry's title: ")) with io.open(fd, 'w', encoding='utf-8') as f: f.write(tt(title, datetime.now().strftime(conf['date_format']))) entry = readers.Entry(tmp, conf) p = join(conf['content_dir'], splitext(entry.permalink.strip('/'))[0]) try: os.makedirs(p.rsplit('/', 1)[0]) except OSError: pass filepath = p + ext if isfile(filepath): raise AcrylamidException('Entry already exists %r' % filepath) shutil.move(tmp, filepath) event.create('new', filepath) if datetime.now().hour == 23 and datetime.now().minute > 45: log.info("notice don't forget to update entry.date-day after mignight!") if log.level() >= log.WARN: return try: if editor: retcode = subprocess.call(shlex.split(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!')