def edit_new_post(post_title, post_dirpath): filename = post_dirpath + "/post.html" # Initialize new post with default content try: post_file = open(filename, 'wb') except IOError as e: print "Failed to open post file: {}".format(e.strerror) return False except Exception as e: print "Unknown error occurred while opening new post file!" logging.debug("Exception info: {}".format(type(e))) return False post_file.write(defaults.DEFAULT_POST_CONTENT.format(post_title)) post_file.close() glue.spawn_editor(filename)
def do_init(args): """ Attempt to initialize a blag with a given name. 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 args: make sure it contains a valid directory name. * Create the blag directory * Initialize a default .blag * Drop the user to his favourite editor to edit it. 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. """ logging.debug("do_init: " + str(args)) # Validate args: make sure it contains a directory name. if len(args) < 1: usage.print_do_init_usage() return 1 dirname = args[0] if not create_blag_dir(dirname): print "Failed to create blag directory {}".format(dirname) print "Exiting..." return 1 if not initialize_default_dotblag(dirname): print "Failed to initialize default settings." print "Exiting..." return 1 if not create_default_blag_elements(dirname): print "Failed to initialize default blag elements." print "Exiting..." return 1 if not glue.spawn_editor("{}/.blag".format(dirname)): logging.debug("Blag created but editor could not be spawned.") return 1 return 0