Beispiel #1
0
def do_crank(args):
    """ Cranks posts """

    crt_path = os.getcwd()

    if not glue.move_to_blag_root():
        print "You do not seem to be inside a blag!"
        os.chdir(crt_path)
        return 1

    if not glue.initvars():
        return 1

    posts = procposts.posts_list()

    for post in posts:
        logging.debug("Processing {}".format(post.path))
        processed_text = process(post)
        write_post(post, processed_text)
        copy_static(post)

    ip = make_index_page()
    write_page("out/index.html", ip);

    ap = make_archive_page()
    write_page("out/archive.html", ap);

    crank_pages()

    return 0
Beispiel #2
0
def do_posts(args):
    """ List posts """
    
    crt_path = os.getcwd()

    if not glue.move_to_blag_root():
        print "You do not seem to be inside a blag."
        os.chdir(crt_path)
        return 1

    posts = procposts.posts_list()

    for post in posts:
        print "{}: {}".format(post.link(), post.title())

    os.chdir(crt_path)
    
    return 0
Beispiel #3
0
def do_post(args):
    """ Attempt to create a new (empty) post
    Args:
        args (array[str]): argv received, starting with argv[2].
    
    Returns:
       0 -- Success
       Any positive value -- Fail

    Raises:
       N/A

    The following steps are wrapped in this function:
    * Validate and parse the arguments received.
    * Prompt the user for date and title if either was not given as
      command-line argument.
    * Initialize the directory structure of the post.
    * Create the new post, empty save for the user-supplied title.

    Any failure in one of these steps will generate an error that is
    printed to stderr. An error in any step except for the last one
    is considered fatal, but no cleanup is attempted there.
    
    """

    crt_path = os.getcwd()

    if not glue.move_to_blag_root():
        print "You do not seem to be inside a blag."
        os.chdir(crt_path)
        return 1

    date_given, post_date = do_post_get_date(args)
    post_given, post_title = do_post_get_title(args)

    if date_given == True:
        if post_date is None:
            print "Missing date!"
            usage.print_do_post_usage()
            os.chdir(crt_path)
            return 1
        if not valid_date(post_date):
            print "Bad date given!"
            os.chdir(crt_path)
            return 1

    if post_given == True and post_title is None:
        print "Missing or ill-formatted title!"
        usage.print_do_post_usage()
        os.chdir(crt_path)
        return 1

    if post_date is None:
        post_date = do_post_prompt_for_date()
    
    if post_title is None:
        post_title = do_post_prompt_for_title()

    logging.debug("Posting {} dated {}".format(post_title, post_date))

    post_dir_path = make_post_dir_structure(post_title, post_date)

    if post_dir_path is None:
        print "Failed to make post directory structure!"
        os.chdir(crt_path)
        return 1

    edit_new_post(post_title, post_dir_path)

    os.chdir(crt_path)

    return 0