Esempio n. 1
0
File: cli.py Progetto: Camr0n/ark
def cmd_edit(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    args = parser.get_args()
    if len(args) < 2:
        sys.exit("Error: the 'edit' command requires at least 2 arguments.")

    paths = [site.src('[%s]' % args[0], path) for path in args[1:]]

    for path in paths:
        if not os.path.exists(path):
            now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            template = "---\ntitle: Record Title\ndate: %s\n---\n\n\n"
            utils.writefile(path, template % now)

    paths.insert(0, os.getenv('ARK_EDITOR') or os.getenv('EDITOR') or 'vim')
    subprocess.call(paths)
Esempio n. 2
0
File: cli.py Progetto: Camr0n/ark
def cmd_init(parser):
    initdir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'ini')
    sitedir = parser.get_args()[0] if parser.has_args() else '.'
    os.makedirs(sitedir, exist_ok=True)
    os.chdir(sitedir)

    for name in ('ext', 'inc', 'lib', 'out', 'src'):
        os.makedirs(name, exist_ok=True)
    utils.writefile('.ark', '')

    if not os.path.exists('config.py'):
        shutil.copy2(os.path.join(initdir, 'config.py'), 'config.py')

    for name in ('ext', 'lib'):
        utils.copydir(os.path.join(initdir, name), name, noclobber=True)

    if not parser['empty']:
        for name in ('inc', 'src'):
            utils.copydir(os.path.join(initdir, name), name, noclobber=True)
Esempio n. 3
0
def cmd_edit(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    args = parser.get_args()
    if len(args) < 2:
        sys.exit("Error: the 'edit' command requires at least 2 arguments.")

    paths = [site.src('[%s]' % args[0], path) for path in args[1:]]

    for path in paths:
        if not os.path.exists(path):
            now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            template = "---\ntitle: Record Title\ndate: %s\n---\n\n\n"
            utils.writefile(path, template % now)

    editor = os.getenv('ARK_EDITOR') or os.getenv('EDITOR') or 'vim'
    if not shutil.which(editor):
        sys.exit("Error: cannot locate the editor '%s'." % editor)

    paths.insert(0, editor)
    subprocess.call(paths)
Esempio n. 4
0
def cmd_init(parser):
    initdir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'ini')
    sitedir = parser.get_args()[0] if parser.has_args() else '.'
    os.makedirs(sitedir, exist_ok=True)
    os.chdir(sitedir)

    for name in ('ext', 'inc', 'lib', 'out', 'src'):
        os.makedirs(name, exist_ok=True)
    utils.writefile('.ark', '')

    if not os.path.exists('config.py'):
        shutil.copy2(os.path.join(initdir, 'config.py'), 'config.py')

    ext = os.path.join(initdir, 'ext')
    utils.copydir(ext, 'ext', noclobber=True)

    for dirinfo in utils.subdirs(os.path.join(initdir, 'lib')):
        if not dirinfo.name in ('debug'):
            dstdir = os.path.join('lib', dirinfo.name)
            utils.copydir(dirinfo.path, dstdir, noclobber=True)

    if not parser['empty']:
        for name in ('inc', 'src'):
            utils.copydir(os.path.join(initdir, name), name, noclobber=True)