コード例 #1
0
ファイル: cli.py プロジェクト: Camr0n/ark
def cmd_watch(parser):
    home = site.home()
    args = [sys.argv[0], 'build', 'watching'] + parser.get_args()

    print("-" * 80)
    print("Site: %s" % home)
    print("Stop: Ctrl-C")
    print("-" * 80)

    # Build the site at least once with the 'watching' flag.
    print("Running intial build.")
    subprocess.call(args)
    print("-" * 80)

    # Create a hash digest of the site directory.
    oldhash = hashsite(home)

    # Loop until the user hits Ctrl-C.
    try:
        while True:
            newhash = hashsite(home)
            if newhash != oldhash:
                print("Building site.")
                subprocess.call(args)
                newhash = hashsite(home)
            oldhash = newhash
            time.sleep(0.5)
    except KeyboardInterrupt:
        pass

    # Build the site one last time without the 'watching' flag.
    print("\n" + "-" * 80 + "Running final build.\n" + "-" * 80)
    subprocess.call(arg for arg in args if arg != 'watching')
コード例 #2
0
ファイル: cli.py プロジェクト: wannaphong/ark
def cmd_watch(parser):
    home = site.home()
    args = [sys.argv[0], 'build', 'watching'] + parser.get_args()

    print("-" * 80)
    print("Site: %s" % home)
    print("Stop: Ctrl-C")
    print("-" * 80)

    # Build the site at least once with the 'watching' flag.
    subprocess.call(args + ['firstwatch'])
    print("-" * 80)

    # Create a hash digest of the site directory.
    oldhash = hashsite(home)

    # Loop until the user hits Ctrl-C.
    try:
        while True:
            newhash = hashsite(home)
            if newhash != oldhash:
                subprocess.call(args)
                newhash = hashsite(home)
            oldhash = newhash
            time.sleep(0.5)
    except KeyboardInterrupt:
        pass

    # Build the site one last time without the 'watching' flag.
    print("\n" + "-" * 80)
    args.remove('watching')
    subprocess.call(args + ['lastwatch'])
    print("-" * 80)
コード例 #3
0
ファイル: cli.py プロジェクト: Camr0n/ark
def cmd_serve(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if not os.path.exists(site.out()):
        sys.exit("Error: cannot locate the site's output directory.")

    os.chdir(site.out())

    try:
        server = http.server.HTTPServer(
            (parser['host'], parser['port']),
            http.server.SimpleHTTPRequestHandler
        )
    except PermissionError:
        sys.exit("Permission error: use 'sudo' to run on a port number below 1024.")

    address = server.socket.getsockname()

    print("-" * 80)
    print("Root: %s" % site.out())
    print("Host: %s"  % address[0])
    print("Port: %s" % address[1])
    print("Stop: Ctrl-C")
    print("-" * 80)

    if parser['browser']:
        webbrowser.open("http://%s:%s" % (parser['host'], parser['port']))

    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("\n" + "-" * 80 + "Stopping server...\n" + "-" * 80)
        server.server_close()
コード例 #4
0
ファイル: cli.py プロジェクト: wannaphong/ark
def cmd_serve(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if not os.path.exists(site.out()):
        sys.exit("Error: cannot locate the site's output directory.")

    os.chdir(site.out())

    try:
        server = http.server.HTTPServer((parser['host'], parser['port']),
                                        http.server.SimpleHTTPRequestHandler)
    except PermissionError:
        sys.exit(
            "Permission error: use 'sudo' to run on a port number below 1024.")

    address = server.socket.getsockname()

    print("-" * 80)
    print("Root: %s" % site.out())
    print("Host: %s" % address[0])
    print("Port: %s" % address[1])
    print("Stop: Ctrl-C")
    print("-" * 80)

    if parser['browser']:
        webbrowser.open("http://%s:%s" % (parser['host'], parser['port']))

    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("\n" + "-" * 80 + "Stopping server...\n" + "-" * 80)
        server.server_close()
コード例 #5
0
ファイル: cli.py プロジェクト: Camr0n/ark
def cmd_clear(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if not os.path.exists(site.out()):
        sys.exit("Error: cannot locate the site's output directory.")

    utils.cleardir(site.out())
コード例 #6
0
ファイル: cli.py プロジェクト: wannaphong/ark
def cmd_clear(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if not os.path.exists(site.out()):
        sys.exit("Error: cannot locate the site's output directory.")

    utils.cleardir(site.out())
コード例 #7
0
ファイル: cli.py プロジェクト: 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)
コード例 #8
0
ファイル: cli.py プロジェクト: wannaphong/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)

    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)
コード例 #9
0
ファイル: cli.py プロジェクト: Camr0n/ark
def cmd_build(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if parser['out']: site.setconfig('[out]', parser['out'])
    if parser['src']: site.setconfig('[src]', parser['src'])
    if parser['lib']: site.setconfig('[lib]', parser['lib'])
    if parser['inc']: site.setconfig('[inc]', parser['inc'])

    if parser['theme']:
        site.setconfig('[theme]', site.find_theme(parser['theme']))

    if parser['clear']:
        utils.cleardir(site.out())

    site.setconfig('[flags]', parser.get_args())

    @hooks.register('main')
    def build_callback():
        if os.path.isdir(site.src()):
            build.build_site()
        else:
            sys.exit("Error: cannot locate the site's source directory.")
コード例 #10
0
ファイル: cli.py プロジェクト: wannaphong/ark
def cmd_build(parser):
    if not site.home():
        sys.exit("Error: cannot locate the site's home directory.")

    if parser['out']: site.setconfig('[out]', parser['out'])
    if parser['src']: site.setconfig('[src]', parser['src'])
    if parser['lib']: site.setconfig('[lib]', parser['lib'])
    if parser['inc']: site.setconfig('[inc]', parser['inc'])

    if parser['theme']:
        site.setconfig('[theme]', site.find_theme(parser['theme']))

    if parser['clear']:
        utils.cleardir(site.out())

    site.setconfig('[flags]', parser.get_args())

    @hooks.register('main')
    def build_callback():
        if os.path.isdir(site.src()):
            build.build_site()
        else:
            sys.exit("Error: cannot locate the site's source directory.")