pubs/pubs/commands/init_cmd.py
Fabien C. Y. Benureau dc4e118c3c make utf8 citekeys possible in python 2.7. closes #28
This involved many changes, some side effects of the change include:
- remove of all `u"abc"` forms, in favor of
  `from __future__ import unicode_literals`. Their usage was
  inconsistent anyway, leading to problems when mixing with
  unicode content.
- improve the tests, to allow printing for usecase even when
  crashing. Should make future test easier. This is done with a
  rather hacky `StdIO` class in `p3`, but it works.
- for some reason, the skipped test for Python 2 seems to work
  now. While the previous point might seem related, it is not clear
  that this is actually the case.
2018-04-10 14:45:54 +09:00

51 lines
1.5 KiB
Python

# init command
from __future__ import unicode_literals
import os
from ..uis import get_ui
from .. import color
from ..repo import Repository
from ..content import system_path, check_directory
from .. import config
def parser(subparsers, conf):
parser = subparsers.add_parser('init',
help="initialize the pubs directory")
parser.add_argument('-p', '--pubsdir', default=None,
help='directory where to put the pubs repository (if none, ~/.pubs is used)')
parser.add_argument('-d', '--docsdir', default='docsdir://',
help=('path to document directory (if not specified, documents will'
'be stored in /path/to/pubsdir/doc/)'))
return parser
def command(conf, args):
"""Create a .pubs directory"""
ui = get_ui()
pubsdir = args.pubsdir
docsdir = args.docsdir
if pubsdir is None:
pubsdir = '~/.pubs'
pubsdir = system_path(pubsdir)
if check_directory(pubsdir, fail=False) and len(os.listdir(pubsdir)) > 0:
ui.error('Directory {} is not empty.'.format(
color.dye_err(pubsdir, 'filepath')))
ui.exit()
ui.message('Initializing pubs in {}'.format(color.dye_out(pubsdir, 'filepath')))
conf['main']['pubsdir'] = pubsdir
conf['main']['docsdir'] = docsdir
conf['main']['open_cmd'] = config.default_open_cmd()
conf = config.post_process_conf(conf)
config.save_conf(conf)
Repository(conf, create=True)