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: title = u(' '.join(options.title)) else: title = u(raw_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'], 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('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([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 do_summary(conf, env, options): limit = options.max if options.max > 0 else 5 entrylist, pages, translations, drafts = readers.load(conf) entrylist = sorted(entrylist + translations + drafts, key=lambda k: k.date, reverse=True) print() print('Acrylamid', blue(env['version']) + ',', end=' ') 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)), end=' ') 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])), end=' ') print('%s drafted articles' % blue(len([e for e in entrylist if e.draft]))) if not isfile(join(conf.get('cache_dir', '.cache/'), 'info')): return time = localtime(getmtime(join(conf.get('cache_dir', '.cache/'), 'info'))) print('last compilation at %s' % blue(u(strftime(u'%d. %B %Y, %H:%M', time))))
def load(path): """Load default configuration, prepare namespace and update configuration with `conf.py`'s uppercase values and normalizes ambiguous values. """ conf = Configuration(defaults.conf) ns = dict([(k.upper(), v) for k, v in iteritems(defaults.conf)]) os.chdir(dirname(find(basename(path), u(dirname(path) or os.getcwd())))) if PY2K: execfile(path, ns) else: exec(compile(open(path).read(), path, 'exec'), ns) conf.update(dict([(k.lower(), ns[k]) for k in ns if k.upper() == k])) # append trailing slash to *_dir and place certain values into an array return defaults.normalize(conf)
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 strftime(self, fmt): return u(datetime.strftime(self, fmt))
def translate_path(self, path): path = SimpleHTTPRequestHandler.translate_path(self, path) return joinurl(u(os.getcwd()), self.www_root, path[len(u(os.getcwd())):])