コード例 #1
0
def choose_action(tree: str, action_name: str, optional: str = None):
    if action_name in ["--update", "-u"]:
        update(tree)
    elif action_name in ["--show", "-sh"]:
        phy_tree: PhyTree
        if re.match(r'[\S]*\.newick$', tree):
            phy_tree = load_tree(tree)
        elif re.match(r'\([\S ]+\}\;$', tree):
            phy_tree = PhyTree()
            try:
                phy_tree.parse_string(tree)
            except ValueError as e:
                print(e)
                exit()
        else:
            print("Post tree as a filename or string")
            exit()
        visualize_tree(phy_tree.get_newick()[0])
    elif action_name in ["--create", "-c"]:
        create(tree)
    elif action_name in ["--random-tree", "-r"]:
        if optional is None:
            random_tree(tree)
        else:
            random_tree(tree, int(optional))
    elif action_name in ["--cut"]:
        cut(tree)
    else:
        print("Wrong name function")
コード例 #2
0
ファイル: server.py プロジェクト: NoRedInk/elm-flasked
def api():
    blob = request.get_json()
    app.model = update(blob, app.model)

    return jsonify({
        'model': app.model
    })
コード例 #3
0
ファイル: gists.py プロジェクト: jiahut/gists.cli
def main():

    #print ''

    log.setDebug(util.argv(_cmds['Debug']))
    actions.supress(util.argv(_cmds['Supress']))

    args = sys.argv

    if len(args) == 1:
        log.comment(
            "No arguments specified, listing your Gists. Try '%s help' if you need help."
            % util.fileName)
        print('')

    del args[0]  # Delete the filename
    cmd = None

    log.debug("Arguments " + str(args))

    #--------------------------------------------
    # If args[0] is a command. We remove it from the list. args now contains only the  command arguments
    # else we keep as is and try to evaluate the command
    #--------------------------------------------
    if _hasCmd(args):
        cmd = args[0]
        del args[
            0]  # Delete the command. Arguments remaining are the options for each command
    else:
        cmd = _deriveCmd(args)

    log.debug("Adjusted cmd: " + str(cmd))
    log.debug("Adjusted arguments " + str(args))
    #--------------------------------------------
    # Handle commands
    #--------------------------------------------
    if cmd == None:
        _printNoMatch()
    elif cmd in (_cmds['Help']):
        actions.help()
    elif cmd in (_cmds['List']):
        actions.list()
    elif cmd in (_cmds['Token']):
        actions.updateCredentials()
    elif cmd in (_cmds['Open']):
        if len(args) == 1:
            actions.open(args[0])
        else:
            _printNoMatch()
    elif cmd in (_cmds['View']):
        if len(args) == 1:
            actions.view(args[0])
        elif len(args) == 2:
            actions.view(args[0], fileName=args[1])
    elif cmd in (_cmds['Download']):
        if len(args) == 2:
            actions.get(args[0], path=args[1])
        elif len(args) == 3:
            actions.get(args[0], fileName=args[1], path=args[2])
    elif cmd in (_cmds['New']):
        # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description.
        if len(args) == 0:
            actions.new()
        elif len(args) == 1:
            # create File
            # create Content
            if util.isFileOrDir(args[0]) == True:
                actions.new(filename=args[0])
            else:
                actions.new(content=args[0])
        elif len(args) == 2:
            # create Boolean and File
            # create Boolean and Content
            # create Description and File
            # create Description and Content
            if util.parseBool(args[0]) != None:
                if util.isFileOrDir(args[1]) == True:
                    actions.new(public=util.parseBool(args[0]),
                                filename=args[1])
                else:
                    actions.new(public=util.parseBool(args[0]),
                                content=args[1])
            else:
                if util.isFileOrDir(args[1]) == True:
                    actions.new(description=args[0], filename=args[1])
                else:
                    actions.new(description=args[0], content=args[1])
        elif len(args) == 3 and util.parseBool(args[0]) != None:
            # create Boolean, Description and File
            # create Boolean, Description and Content
            if util.isFileOrDir(args[2]) == True:
                actions.new(public=util.parseBool(args[0]),
                            description=args[1],
                            filename=args[2])
            else:
                actions.new(public=util.parseBool(args[0]),
                            description=args[1],
                            content=args[2])
        else:
            _printNoMatch()
    elif cmd in (_cmds['Append']):
        # Each option will prompt for public/pvt and description.
        if len(args) == 0:
            _printNoMatch()
        elif len(args) == 2:
            # append: id File
            # append: id Content
            if util.isFileOrDir(args[1]) == True:
                actions.append(args[0], filename=args[1])
            else:
                actions.append(args[0], content=args[1])
        elif len(args) == 3:
            # append: id Description File
            # append: id Description Content
            if util.isFileOrDir(args[2]) == True:
                actions.append(args[0], description=args[1], filename=args[2])
            else:
                actions.append(args[0], description=args[1], content=args[2])
        else:
            actions.append(args[0])
    elif cmd in (_cmds['Update']):
        # Each option will prompt for public/pvt and description.
        if len(args) == 0:
            _printNoMatch()
        elif len(args) == 2:
            # append: id File
            # append: id Content
            if util.isFileOrDir(args[1]) == True:
                actions.update(args[0], filename=args[1])
            else:
                actions.update(args[0], content=args[1])
        elif len(args) == 3:
            # append: id Description File
            # append: id Description Content
            if util.isFileOrDir(args[2]) == True:
                actions.update(args[0], description=args[1], filename=args[2])
            else:
                actions.update(args[0], description=args[1], content=args[2])
        else:
            actions.update(args[0])
    elif cmd in (_cmds['Delete']):
        actions.delete(args[0])
    elif cmd in (_cmds['Backup']):
        _printNoImpl()
        actions.backup()
    elif cmd in (_cmds['Search']):
        _printNoImpl()
        actions.search()
    else:
        _printNoMatch()

    log.debug("Done.")
    print('')
コード例 #4
0
ファイル: stock.py プロジェクト: abhinavydv/MedicalStore
def update():
    print("Update options:")
    print("2. Update using batch no.")
    print("3. Update using condition")
    print("0. Home")
    print("1. Medicine Information")
    ch = input("Enter your choice: ")

    condition = '1=1'

    while ch not in '0123' or len(ch) != 1:
        ch = input("Invalid choice! Please enter again: ")

    if ch == '0':
        return 0

    elif ch == '1':
        return '1'

    elif ch == '2':
        batch = input("Enter batch no. of stock: ")
        while not batch.isdigit():
            batch = input(
                "Batch no. should be an integer only! Please enter again: ")

        condition = f"BatchNo='{batch}'"

    elif ch == '3':
        print("All columns are: ")
        print(actions.get_columns("Stock"))
        condition = input(
            'Enter condition(<column_name><operator>"<value>"): ')
        while True:
            try:
                cur.execute(f"select 1+2 where {condition}")
                cur.fetchall()
                break
            except Exception as e:
                print(e)
                condition = input(
                    'Your condition had above error! Enter again(<column_name><operator>"<value>"): '
                )

    if ch in '23' and len(ch) == 1:
        columns_all = actions.get_columns("Stock")
        col_dict = {i + 1: columns_all[i] for i in range(len(columns_all))}
        print(col_dict)
        column = input("Which column no. do you want to update: ").lower()
        while column not in col_dict:
            column = input(
                "Column you entered is not in table! Enter again: ").lower()
        column = col_dict[int(column)]
        val = input("Enter value: ")
        try:
            actions.update("Stock", column, val, condition)
            print("Updated successfully...")
        except Exception as e:
            print("An error occurred!!  Error code: 021" if ch ==
                  '2' else "Your condition had an error!!")
            print(e)
            traceback.print_exc()
コード例 #5
0
def update():
    print("Update options:")
    print("2. Update using barcode")
    print("3. Update using name")
    print("4. Update using condition")
    print("0. Home")
    print("1. Medicine Information")
    ch = input("Enter your choice: ")
    condition = '1=1'

    while ch not in '01234' or len(ch) != 1:
        ch = input("Invalid choice! Please enter again: ")

    if ch == '0':
        return 0

    elif ch == '1':
        return '1'

    elif ch == '2':
        bar = input("Enter barcode of medicine: ")
        while not bar.isdigit():
            bar = input(
                "Barcode should be an integer only! Please enter again: ")

        condition = f"Barcode='{bar}'"

    elif ch == '3':
        name = input("Enter name of medicine: ")
        condition = f"Name='{name}'"

    elif ch == '4':
        print("All columns are")
        print(actions.get_columns("MedicineInfo"))
        condition = input(
            'Enter condition(<column_name><operator>"<value>"): ')
        while True:
            try:
                cur.execute(f"select 1+2 from MedicineInfo where {condition}")
                cur.fetchall()
                break
            except Exception as e:
                print(e)
                condition = input(
                    'Your condition had above error! \nEnter again(<column_name><operator>"<value>"): '
                )

    if ch in '234' and len(ch) == 1:
        columns_all = actions.get_columns("MedicineInfo")
        col_dict = {i + 1: columns_all[i] for i in range(len(columns_all))}
        print(col_dict)
        column = input("Which column no. do you want to update: ").lower()
        while not column.isdigit() or int(column) not in col_dict:
            column = input(
                "Column no. you entered is not in option! Enter again: "
            ).lower()
        column = col_dict[int(column)]
        val = input("Enter value: ")
        try:
            actions.update("MedicineInfo", column, val, condition)
            print("Updated records successfully...")
        except Exception as e:
            print("Your condition had below error!")
            print(e)
コード例 #6
0
ファイル: gists.py プロジェクト: khilnani/gists.cli
def main ( ):

  #print ''

  log.setDebug( util.argv( _cmds['Debug'] ) )
  actions.supress( util.argv( _cmds['Supress']) )

  args = sys.argv
  
  if len(args) == 1:
    log.comment ("No arguments specified, listing your Gists. Try '%s help' if you need help." % util.fileName)
    print ''

  del args[0] # Delete the filename
  cmd = None

  log.debug ("Arguments " + str( args ))

  #--------------------------------------------
  # If args[0] is a command. We remove it from the list. args now contains only the  command arguments
  # else we keep as is and try to evaluate the command
  #--------------------------------------------
  if _hasCmd( args ):
    cmd = args[0]
    del args[0] # Delete the command. Arguments remaining are the options for each command
  else:
    cmd = _deriveCmd( args )

  log.debug ("Adjusted cmd: " + str(cmd))
  log.debug ("Adjusted arguments " + str( args ))
  #--------------------------------------------
  # Handle commands
  #--------------------------------------------
  if cmd == None:
    _printNoMatch()
  elif cmd in (_cmds['Help']):
    actions.help()
  elif cmd in (_cmds['List']):
    actions.list()
  elif cmd in (_cmds['Token']):
    actions.updateCredentials()
  elif cmd in (_cmds['View']):
    if len(args) == 1:
      actions.view( args[0] )
    elif len(args) == 2:
      actions.view( args[0], fileName=args[1])
  elif cmd in (_cmds['Download']):
    if len(args) == 2:
      actions.get( args[0], path=args[1] )
    elif len(args) == 3:
      actions.get( args[0], fileName=args[1], path=args[2] )
  elif cmd in (_cmds['New']):
    # Each option will prompt for public/pvt and description. In silent mode, assumes private and no description.
    if len(args) == 0:
      actions.new()
    elif len(args) == 1:
      # create File
      # create Content
      if util.isFileOrDir(args[0]) == True:
        actions.new( filename = args[0] )
      else:
        actions.new( content = args[0] )
    elif len(args) == 2: 
      # create Boolean and File
      # create Boolean and Content
      # create Description and File 
      # create Description and Content 
      if util.parseBool( args[0] ) != None:
        if util.isFileOrDir(args[1]) == True:
          actions.new( public=util.parseBool( args[0] ), filename=args[1] )
        else:
          actions.new( public=util.parseBool( args[0] ), content=args[1] )
      else:
        if util.isFileOrDir(args[1]) == True:
          actions.new( description=args[0], filename=args[1] )
        else:
          actions.new( description=args[0], content=args[1] )
    elif len(args) == 3 and util.parseBool( args[0] ) != None:
      # create Boolean, Description and File
      # create Boolean, Description and Content
      if util.isFileOrDir(args[2]) == True:
        actions.new( public=util.parseBool( args[0] ), description=args[1], filename=args[2] )
      else:
        actions.new( public=util.parseBool( args[0] ), description=args[1], content=args[2] )
    else:
      _printNoMatch()
  elif cmd in (_cmds['Append']):
    # Each option will prompt for public/pvt and description.
    if len(args) == 0:
      _printNoMatch()
    elif len(args) == 2: 
      # append: id File
      # append: id Content 
      if util.isFileOrDir(args[1]) == True:
        actions.append( args[0], filename=args[1] )
      else:
        actions.append( args[0], content=args[1] )
    elif len(args) == 3:
      # append: id Description File
      # append: id Description Content
      if util.isFileOrDir(args[2]) == True:
        actions.append( args[0], description=args[1], filename=args[2] )
      else:
        actions.append( args[0], description=args[1], content=args[2] )
    else:
      actions.append( args[0] )
  elif cmd in (_cmds['Update']):
    # Each option will prompt for public/pvt and description.
    if len(args) == 0:
      _printNoMatch()
    elif len(args) == 2: 
      # append: id File
      # append: id Content 
      if util.isFileOrDir(args[1]) == True:
        actions.update( args[0], filename=args[1] )
      else:
        actions.update( args[0], content=args[1] )
    elif len(args) == 3:
      # append: id Description File
      # append: id Description Content
      if util.isFileOrDir(args[2]) == True:
        actions.update( args[0], description=args[1], filename=args[2] )
      else:
        actions.update( args[0], description=args[1], content=args[2] )
    else:
      actions.update( args[0] )
  elif cmd in (_cmds['Delete']):
    actions.delete( args[0] )
  elif cmd in (_cmds['Backup']):
    _printNoImpl()
    actions.backup( )
  elif cmd in (_cmds['Search']):
    _printNoImpl()
    actions.search( )
  else:
    _printNoMatch()

  log.debug ("Done.")
  print ''