示例#1
0
def parseArguments():
    # TODO remove argparse to use the modified argumentParser
    # TODO Account must be unique
    '''
    Parses the arguments of the atmself.
    A Objects is return in which the paramters values are callabel
    '''

    parser = ArgumentParser(conflict_handler='error')

    parser.add_argument("-s", help="""The authentication file that bank creates for the atm.
        If -s is not specified, the default filename is "bank.auth"
        (in the current working directory).
        If the specified file cannot be opened or is invalid,
        the atm exits with a return code of 255.""", dest="authFile",
                        default="bank.auth", metavar="auth_file")

    parser.add_argument("-i", help="""The IP address that bank is running on.
        The default value is "127.0.0.1".""", dest="ip", default="127.0.0.1",
                        metavar="ip-address")

    parser.add_argument("-p", help="""The TCP port that bank is listening on.
                        The default is 3000.""",
                        dest="port", default="3000")

    parser.add_argument("-c", help="""The customer's atm card file.
    The default value is the account name prepended to ".card"
    ("<account>.card"). For example, if the account name was 55555,
    the default card file is "55555.card".""",
                        dest="cardFile", metavar="CARD-FILE")

    parser.add_argument("-a", help="""The customer's account name. """,
                        dest="account", required=False)

    modesParser = parser.add_mutually_exclusive_group()
    modesParser.add_argument("-n", help=""" Create a new account with the given balance.
        The account must be unique (ie, the account must not already exist).
        The balance must be greater than or equal to 10.00. """)

    modesParser.add_argument("-d", help="""Deposit the amount of money specified.
        The amount must be greater than 0.00. The specified account must exist,
        and the card file must be associated with the given account
        (i.e., it must be the same file produced by atm when the account
        was created).""")

    modesParser.add_argument("-w", help="""Withdraw the amount of money specified.
        The amount must be greater than 0.00, and the remaining balance must be
        nonnegative. The card file must be associated with the specified
        account (i.e., it must be the same file produced by atm when the
        account was created).""")

    modesParser.add_argument("-g", help="""Get the current balance of the account.
        The specified account must exist, and the card file must be associated
        with the account.""", action="store_true")

    return parser.parse_args(sys.argv[1:])
示例#2
0
def parseArguments():
    parser = ArgumentParser()
    parser.add_argument('-p',
                        default=3000,
                        help="The port used for "
                        "the bank. If argument is not given, port " +
                        "%d is used." % 3000,
                        dest='port',
                        type=int)
    parser.add_argument('-s',
                        default='bank.auth',
                        help="File name of " +
                        "the auth file. If argument is not given, " +
                        "'%s' is used." % 'bank.auth',
                        dest="authFile")
    return parser.parse_args(argv[1:])
示例#3
0
import shutil
import xml.dom.minidom

def __getCurrentPath():
    return os.path.normpath(os.path.join(os.path.realpath(__file__), os.path.pardir))
sys.path.insert(0, os.path.join(__getCurrentPath(), "libs", 'pytoolkit.zip'))
sys.path.insert(0, os.path.join(__getCurrentPath(), os.path.pardir))

from ArgumentParser import ArgumentParser
from Colorful import *
from MetaDataParser import *
from MetaDataParser.Settings import *

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument("--metadata", type=str, dest='metadata', 
        required=True)
    parser.add_argument("--output", type=str, dest="output", required=True)
    argument = parser.parse_args()
    if not os.path.exists(argument.metadata):
        printColorful("red", "%s 不存在" % argument.metadata)
        sys.exit(1)
        
    if not os.path.exists(argument.output):
        os.makedirs(argument.output)
    
    root = xml.dom.minidom.parse(argument.metadata)
    domainParser = DomainParser(root, argument.output)
    domainParser.generateFiles()
    requestParser = RequestParser(root, argument.output)
    requestParser.generateFiles()
    responseParser = ResponseParser(root, argument.output)