Esempio n. 1
0
def encounter_sing():
    #Define Player Roll
    print Character.attributes
    player_attack = Character.attributes[key][0] + Character.attributes[key][1]
    player_roll = player_attack * random.randrange(1,6,1)
    
    #Define Enemy Roll
    print Enemy.attributes
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Enemy fell asleep. You can escape or take advantage of him."
    	print "We won't judge."
    	choice = raw_input("What are you going to do (run away or take advantage)? ")
    	if choice.lower == 'take advantage':
    	    print "You sicko"
    	else:
    	    print "You're probably a woman anyway."
    	return
    elif player_roll < enemy_roll:
    	print "Enemy wins. Game Over."
    	sys.kill()
    elif player_roll = enemy_roll:
    	print "It's a tie. Try Again."
    	encounter()
Esempio n. 2
0
    def __check_argument(self, kwargs):
        """関数に渡されようとしている引数と型をチェック"""

        if len(kwargs) == 0:
            return True

        if len(kwargs) != self.func_argcount:
            OutOfParserError(
                "option takes exactly %d arguments" % len(self.func_args))
            return False

        for kw_name, kw_value in kwargs.iteritems():
            for arg_name, typeof in self.func_argument_types.iteritems():
                if arg_name == kw_name:
                    try:
                        kwargs[arg_name] = typeof(kw_value)
                    except ValueError:
                        OutOfParserError(
                            "'%s' this argument required '%s' type!" % (
                                arg_name, typeof
                            )
                        )
                        kill(1)

        return True
Esempio n. 3
0
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"))
Esempio n. 4
0
    def __get_option_func(self, hook_in):
        """hook_inが追加したoptionのhooksに存在するかどうか"""
        find_result = False
        for option_obj in self.options:
            if hook_in in option_obj.hooks:
                find_result = True
                break

        if find_result is True:
            return option_obj
        else:
            self.call_usage(self.prog_name)
            kill(1)
Esempio n. 5
0
def default():
    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)

    adjust.output_todolist(todo_container, sortby="status-open")
Esempio n. 6
0
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"))
Esempio n. 7
0
 def invoke(self):
     ##COMMAND PATTERN: CMD FILE_NAME TO_PATH TYPE -> Example: mv /home/test.php /var/www/
     command = self.MSG.split(" ")
     ##CREATE FILE -> Command pattern: mkdir,file_or_directory_name,type
     if (command[0] == 'mkdir'):
         if (command[2] == 0):  ##FILE
             os.mknod(command[1])
             self.con.send(self.INVOKE_SUCCESS.encode())
         else:  ##DIR
             os.mkdir(command[1])
             self.con.send(self.INVOKE_SUCCESS.encode())
     ##REMOVE FILE -> Command pattern: rm file_or_directory_name type
     elif (command[0] == 'rm'):
         if (command[2] == 0):
             ## TRY REMOVE FILE
             try:
                 os.remove(command[1])
                 self.con.send(self.INVOKE_SUCCESS.encode())
             except:
                 print("[+] Error...")
         else:
             ## TRY REMOVE DIRECTORY
             try:
                 shutil.rmtree(command[1])
                 self.con.send(self.INVOKE_SUCCESS.encode())
             except:
                 print("[+] Error...")
     ##RENAME FILE -> Command pattern: mv file_name new_file_name
     elif (command[0] == 'mv'):
         os.rename(comamnd[1], command[2])
         self.con.send(self.INVOKE_SUCCESS.encode())
     ##LIST FILE -> Command pattern: ls dir
     elif (command[0] == 'ls'):
         result = str(os.listdir(command[1])) + "\n"
         self.con.send(result.encode())
         self.con.send(self.INVOKE_SUCCESS.encode())
     ##COPY FILE OR DIRECTORY -> Command pattern: cp from to type
     elif (command[0] == 'cp'):
         if (command[3] == 0):  # IS FILE
             shutil.copy2(command[1], command[2])
             reself.con.send(self.INVOKE_SUCCESS.encode())
         else:  # IS DIRECTORY
             copy_tree(command[1], command[2])
             self.con.send(self.INVOKE_SUCCESS.encode())
     ##LIST FILE
     elif (command[0] == 'quit'):
         sys.kill()
     else:
         self.con.send(self.INVOKE_ERROR.encode())
Esempio n. 8
0
def show_log():
    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_container = core.load_state(open(CACHE_FILE_PATH,"r"))
    commits = adjust.get_commits()
    pager = get_pager()
    isoformat = "%a %b %d %H:%M:%S %Y %z"
    

    io = StringIO()
    sys.stdout = io

    for commit in commits:
        print yellow("commit: %s" % commit.commithash)

        opened_commits = ([blue("'"+t.content+"'") for t in todo_container \
                                if t.opened_commit == commit.commithash])
        closed_commits = ([red("'"+t.content+"'") for t in todo_container \
                                if t.closed_commit == commit.commithash])

        if len(opened_commits) != 0:
            print "Opened ToDo: %s" % ", ".join(opened_commits)
        if len(closed_commits) != 0:
            print "Closed ToDo: %s" % ", ".join(closed_commits)

        if commit.merge_data != None:
            print "Merge: %s" % " ".join(commit.merge_data)
            print "Author: %s <%s>" % (
                    commit.author.name,
                    commit.author.email)
        else:
            print "Author: %s <%s>" %  (
                    commit.author.name,
                    commit.author.email)
        print "Date: %s" % commit.date.strftime(isoformat)
        print 
        print commit.comment
        print 
    
    sys.stdout = sys.__stdout__
    if pager == None:
        print io.getvalue()[:-1]
    else:
        proc = Popen(pager.split(" "), stdin=PIPE, stderr=PIPE)
        proc.communicate(io.getvalue()[:-1])
Esempio n. 9
0
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"
Esempio n. 10
0
async def run_lavalink():
    print("Iniciando Lavalink...")
    global lavalink_process
    lavalink_process = Popen(['java', '-jar', 'Lavalink.jar'],
                             cwd='./java/lavalink')
    global lavalink_tries
    if lavalink_tries < 3:
        if lavalink_process.poll == None:
            print('Tentando reineicar o lava link')
            lavalink_tries += 1
            run_lavalink()
    else:
        print('O lavalink caiu mais de 3 vezes, proecsso desligado')
        bot_process.kill()
        lavalink_process.kill()
        sys.kill(1)
Esempio n. 11
0
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"))
Esempio n. 12
0
def encounter_magic():
    #Define Player Roll
    print Character.attributes
    player_attack = Character.attributes[key][0] + Character.attributes[key][1]
    player_roll = player_attack * random.randrange(1,6,1)
    
    #Define Enemy Roll
    print Enemy.attributes
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Enemy defeated by spell."
    	return
    elif player_roll < enemy_roll:
    	print "Spell failed. Enemy defeats you. Game Over."
    	sys.kill()
    elif player_roll = enemy_roll:
    	print "Your spell was absorbed. Try Again."
    	encounter()
Esempio n. 13
0
def encounter_attack():
    #Define Player Roll
    print Character.attributes
    player_attack = Character.attributes[key][0] + Character.attributes[key][1]
    player_roll = player_attack * random.randrange(1,6,1)
    
    #Define Enemy Roll
    print Enemy.attributes
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Enemy defeated"
    	return
    elif player_roll < enemy_roll:
    	print "Enemy has defeated you. Game Over."
    	sys.kill()
    elif player_roll = enemy_roll:
    	print "You were blocked. Try Again."
    	encounter()
Esempio n. 14
0
def encounter_steal():
    #Define Player Roll
    print Character.attributes
    player_attack = Character.attributes[key][0] + Character.attributes[key][1]
    player_roll = player_attack * random.randrange(1,6,1)
    
    #Define Enemy Roll
    print Enemy.attributes
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Succussfully stole enemy gold"
    	return
    elif player_roll < enemy_roll:
    	print "You were caught and are going to jail. Game Over."
    	sys.kill()
    elif player_roll = enemy_roll:
    	print "Unsuccessful. Try Again."
    	encounter()
Esempio n. 15
0
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"))
Esempio n. 16
0
def todo_information(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)-1:
        print "The Index value is over the number of todo."
        kill(1)
        
    todo = todo_container[index]
    timeformat = core.isoformat.replace("-"," ")

    print "%s" % yellow("#%d"%index)
    print "[%s]" % (blue(todo.status) if todo.status == "OPEN"
                                        else red(todo.status)),
    print todo.content
    print "-"*core.terminal_width()
    
    print "Author".ljust(13),":",magenta(todo.author)
    print "Primary Id".ljust(13),":",todo.hashid
    print "Created at".ljust(13), ":", todo.created_at.strftime(
                                                     timeformat)
    if todo.status == "CLOSED":
        print "Closed at".ljust(13), ":", todo.closed_at.strftime(
                                                            timeformat)
    print "Opened commit", ":", blue(todo.opened_commit)

    if todo.status == "CLOSED":
        print "Closed commit", ":", red(todo.closed_commit)
        print "-"*core.terminal_width()
Esempio n. 17
0
    def parse(self, target=argv):
        """コマンドラインオプションをパース。target引数でパースするものを指定できます"""
        self.prog_name = target[0].split("/")[-1]

        # ヘルプとバージョンをprintするoptionを追加
        self.__add_usage_opt()
        if self.app_version:
            self.__add_version_opt()

        if self.is_exist_no_hook_option is True:

            if len(target) < 2:
                # no argument default option
                self.no_hook_command.run()
                return

            elif len(target) >= 2:
                option_arguments_values = target[1:]
                option_arguments = dict(zip(
                    self.no_hook_command.func_args, option_arguments_values
                ))

                # 指定された引数がDefaultOptionのものなのか、定義済のOptionのHookなのかを判定
                is_default_option_arg = None
                hooks = [i.hooks for i in self.options]

                for hook in hooks:
                    for value in option_arguments_values:
                        if value not in hook:
                            # 定義済OptionのHookには含まれていないのでDefaultOptionの引数
                            is_default_option_arg = True
                        else:
                            is_default_option_arg = False
                            break

                    if is_default_option_arg is False:
                        break

                if is_default_option_arg is True:
                    self.no_hook_command.run(option_arguments)
                    return

        else:
            if len(target) < 2:
                self.call_usage(self.prog_name)
                kill(1)

        hook_in = target[1]

        option_obj = self.__get_option_func(hook_in)

        option_arguments_values = target[2:]
        if option_obj.func_argcount != len(option_arguments_values):
            OutOfParserError(
                "option takes exactly %d arguments" % (
                    len(option_obj.func_args),
                )
            )
            kill(1)

        option_arguments = dict(
            zip(option_obj.func_args, option_arguments_values))

        if len(option_arguments) != 0:
            option_obj.run(option_arguments)
        else:
            option_obj.run()
Esempio n. 18
0
    # 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"

@parser.option("import",
    description=yellow("This is Only Development option")+ \
                    " You can import ToDo data from backup file.")
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"))
    
if __name__ == "__main__":
    if check_exist_repo() == False:
        print yellow("There is not git repository!")
        kill(1)

    parser.parse()
Esempio n. 19
0
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Enemy defeated"
    	return
    elif player_roll < enemy_roll:
    	print "Enemy has defeated you. Game Over."
    	sys.kill()
    elif player_roll = enemy_roll:
    	print "You were blocked. Try Again."
    	encounter()
    else:
    	print "Error with commands or inputs"
    	sys.kill()

def encounter_magic():
    #Define Player Roll
    print Character.attributes
    player_attack = Character.attributes[key][0] + Character.attributes[key][1]
    player_roll = player_attack * random.randrange(1,6,1)
    
    #Define Enemy Roll
    print Enemy.attributes
    enemy_attack = Enemy.attributes[key][0] + Enemy.attributes[key][1]
    enemy_roll = enemy_attack * random.randrange(1,6,1)
    
    #Define Winner
    if player_roll > enemy_roll:
    	print "Enemy defeated by spell."