def move(path): ''' Demotes given file to draft. ''' # get dirname and filename dirname, filename = os.path.split(path) # get docname without extension docname = os.path.splitext(filename)[0] draft = os.path.join(utils.get_path(paths.root, "drafts"), filename) # move file shutil.move(path, draft) # check if file is a post or a page if os.path.basename(dirname) == "pages": docname = "pages/" + docname else: match = re.match(r".*(?P<y>\d{4}).(?P<m>\d{2}).(?P<d>\d{2})$", dirname) if not match: return draft g = match.group docname = "/".join([g("y"), g("m"), g("d"), docname]) # remove file from TOC master.remove_doc(docname) return draft
def test_remove(self): # append 4 docs new_docs = ["a", "b", "c", "d"] for doc in new_docs: master.append_doc(doc) # remove 3 of them while checking master each time for doc_to_remove in ["c", "b", "d"]: master.remove_doc(doc_to_remove) new_docs.remove(doc_to_remove) self.assertEquals( TestMaster.MASTER_HEAD + [" %s\n" % doc for doc in new_docs] + TestMaster.MASTER_TAIL, master.read_master())