def initialize(): # check exist file if os.access(CACHE_FILE_PATH, os.F_OK): print "In this repository, you already initialized." return # create cache file core.save_state([], open(CACHE_FILE_PATH,"w"))
def close_todo(index): if os.access(CACHE_FILE_PATH, os.F_OK) != True: print "The repository does not todo initialized yet." print "Please do 'git todo init'" kill(1) # get todo container todo_container = core.load_state(open(CACHE_FILE_PATH,"r")) if len(todo_container) == 0: print "There is not ToDo." kill(1) if index > len(todo_container): print "The Index value is over the number of todo." kill(1) # check already closed if todo_container[index].status == "CLOSED": print "This ToDo is already closed." kill(1) # create tag put_tag("ToDo#%d_close" % index, "Closed '%s' ToDo."%todo_container[index].content) # change status todo_container[index].status = "CLOSED" todo_container[index].closed_commit = adjust.get_latest_commit().commithash todo_container[index].closed_at = datetime.now() core.save_state(todo_container, open(CACHE_FILE_PATH,"w"))
def import_todo(backup_file): if os.access(backup_file, os.F_OK) == False: print "'%s' file is not found." % backup_file kill(1) fp = open(backup_file,"r") todo_container = core.load_state(fp) core.save_state(todo_container, open(CACHE_FILE_PATH,"w"))
def alldeelete(): if os.access(CACHE_FILE_PATH, os.F_OK) != True: print "The repository does not todo initialized yet." print "Please do 'git todo init'" kill(1) # save todo container data to backup file fp = open("todo_backup","w") todo_container = core.load_state(open(CACHE_FILE_PATH,"r")) core.save_state(todo_container, fp) # delete cache file if os.access(CACHE_FILE_PATH, os.F_OK): core.shellrun("rm", "%s" % CACHE_FILE_PATH) print "Complete"
def delete(index): if os.access(CACHE_FILE_PATH, os.F_OK) != True: print "The repository does not todo initialized yet." print "Please do 'git todo init'" kill(1) # get todo container todo_container = core.load_state(open(CACHE_FILE_PATH,"r")) if len(todo_container) == 0: print "There is not ToDo." kill(1) if index > len(todo_container): print "The Index value is over the number of todo." kill(1) todo_container.pop(index) core.save_state(todo_container, open(CACHE_FILE_PATH,"w"))
def create(content): if os.access(CACHE_FILE_PATH, os.F_OK) != True: print "The repository does not todo initialized yet." print "Please do 'git todo init'" kill(1) # ------------------------------------------------ # ToDo object # 1. id (str) - git hash-object # 2. content(str) - todo content string # 3. author(str) - the author name that create todo # 4. created_at(datetime) - datetime when open todo # 5. status(str) - open or close # 6. opened_commit(str) - commit hash when created todo # 7. closed_at(datetime) - datetime when close todo # 8. closed_commit(str) - commit hash when closed todo # ------------------------------------------------ # get todo container todo_container = core.load_state(open(CACHE_FILE_PATH,"r")) for n,todo in enumerate(todo_container): if todo.content == content: print "fatal: this ToDo is duplicate." print "Your appending ToDo: %s" % content print "duplicate ToDo: %(index)s %(content)s" % { "index": yellow(n), "content":todo.content} kill(1) todo_info = {} todo_info["hashid"] = make_hash(content) todo_info["content"] = content todo_info["author"] = get_author() todo_info["created_at"] = datetime.now() todo_info["status"] = "OPEN" todo_info["opened_commit"] = adjust.get_latest_commit().commithash todo_info["closed_at"] = None todo_info["closed_commit"] = None todo_obj = Todo(**todo_info) todo_container.append(todo_obj) core.save_state(todo_container, open(CACHE_FILE_PATH,"w"))