Exemplo n.º 1
0
def run(sysargs):
    parser = optparse.OptionParser(usage="usage: %prog [FILE] [FILE]",
                                   description=__doc__)
    parser.add_option(
        '-m',
        '--mode',
        type='string',
        dest='mode',
        default='development',
        help="""[development|production] The strictness mode to use
while checking the template; see the wiki page for details about
what is allowed and disallowed by each mode:
http://wiki.secondlife.com/wiki/Template_verifier.py
""")
    parser.add_option(
        '-u',
        '--master_url',
        type='string',
        dest='master_url',
        default=
        'http://secondlife.com/app/message_template/master_message_template.msg',
        help="""The url of the master message template.""")
    parser.add_option(
        '-c',
        '--cache_master',
        action='store_true',
        dest='cache_master',
        default=False,
        help=
        """Set to true to attempt use local cached copy of the master template."""
    )

    options, args = parser.parse_args(sysargs)

    if options.mode == 'production':
        options.cache_master = False

    # both current and master supplied in positional params
    if len(args) == 2:
        master_filename, current_filename = args
        print "master:", master_filename
        print "current:", current_filename
        master_url = 'file://%s' % master_filename
        current_url = 'file://%s' % current_filename
    # only current supplied in positional param
    elif len(args) == 1:
        master_url = None
        current_filename = args[0]
        print "master:", options.master_url
        print "current:", current_filename
        current_url = 'file://%s' % current_filename
    # nothing specified, use defaults for everything
    elif len(args) == 0:
        master_url = None
        current_url = None
    else:
        die("Too many arguments")

    if master_url is None:
        master_url = options.master_url

    if current_url is None:
        current_filename = local_template_filename()
        print "master:", options.master_url
        print "current:", current_filename
        current_url = 'file://%s' % current_filename

    # retrieve the contents of the local template and check for syntax
    current = fetch(current_url)
    current_parsed = llmessage.parseTemplateString(current)

    if options.cache_master:
        # optionally return a url to a locally-cached master so we don't hit the network all the time
        master_url = cache_master(master_url)

    def parse_master_url():
        master = fetch(master_url)
        return llmessage.parseTemplateString(master)

    try:
        master_parsed = retry(3, parse_master_url)
    except (IOError, tokenstream.ParseError), e:
        if options.mode == 'production':
            raise e
        else:
            print "WARNING: problems retrieving the master from %s." % master_url
            print "Syntax-checking the local template ONLY, no compatibility check is being run."
            print "Cause: %s\n\n" % e
            return 0
Exemplo n.º 2
0
 def parse_master_url():
     master = fetch(master_url)
     return llmessage.parseTemplateString(master)
Exemplo n.º 3
0
 def parse_master_url():
     master = fetch(master_url).decode("utf-8")
     return llmessage.parseTemplateString(master)
Exemplo n.º 4
0
 def get_and_test_master():
     new_master_contents = fetch(master_url)
     llmessage.parseTemplateString(new_master_contents)
     return new_master_contents
Exemplo n.º 5
0
def run(sysargs):
    parser = optparse.OptionParser(usage="usage: %prog [FILE] [FILE]",
                                   description=__doc__)
    parser.add_option(
        '-m',
        '--mode',
        type='string',
        dest='mode',
        default='development',
        help="""[development|production] The strictness mode to use
while checking the template; see the wiki page for details about
what is allowed and disallowed by each mode:
http://wiki.secondlife.com/wiki/Template_verifier.py
""")
    parser.add_option(
        '-u',
        '--master_url',
        type='string',
        dest='master_url',
        default=
        'https://bitbucket.org/lindenlab/master-message-template-git/raw/master/message_template.msg',
        help="""The url of the master message template.""")
    parser.add_option(
        '-c',
        '--cache_master',
        action='store_true',
        dest='cache_master',
        default=False,
        help=
        """Set to true to attempt use local cached copy of the master template."""
    )
    parser.add_option(
        '-f',
        '--force',
        action='store_true',
        dest='force_verification',
        default=False,
        help=
        """Set to true to skip the sha_1 check and force template verification."""
    )

    options, args = parser.parse_args(sysargs)

    if options.mode == 'production':
        options.cache_master = False

    # both current and master supplied in positional params
    if len(args) == 2:
        master_filename, current_filename = args
        print("master:", master_filename)
        print("current:", current_filename)
        master_url = 'file://%s' % master_filename
        current_url = 'file://%s' % current_filename
    # only current supplied in positional param
    elif len(args) == 1:
        master_url = None
        current_filename = args[0]
        print("master:", options.master_url)
        print("current:", current_filename)
        current_url = 'file://%s' % current_filename
    # nothing specified, use defaults for everything
    elif len(args) == 0:
        master_url = None
        current_url = None
    else:
        die("Too many arguments")

    if master_url is None:
        master_url = options.master_url

    if current_url is None:
        current_filename = local_template_filename()
        print("master:", options.master_url)
        print("current:", current_filename)
        current_url = 'file://%s' % current_filename

    # retrieve the contents of the local template
    current = fetch(current_url)
    hexdigest = hashlib.sha1(current).hexdigest()
    if not options.force_verification:
        # Early exist if the template hasn't changed.
        sha_url = "%s.sha1" % current_url
        current_sha = fetch(sha_url).decode("utf-8")
        if hexdigest == current_sha:
            print("Message template SHA_1 has not changed.")
            sys.exit(0)

    # and check for syntax
    current_parsed = llmessage.parseTemplateString(current.decode("utf-8"))

    if options.cache_master:
        # optionally return a url to a locally-cached master so we don't hit the network all the time
        master_url = cache_master(master_url)

    def parse_master_url():
        master = fetch(master_url).decode("utf-8")
        return llmessage.parseTemplateString(master)

    try:
        master_parsed = retry(3, parse_master_url)
    except (IOError, tokenstream.ParseError) as e:
        if options.mode == 'production':
            raise e
        else:
            print("WARNING: problems retrieving the master from %s." %
                  master_url)
            print(
                "Syntax-checking the local template ONLY, no compatibility check is being run."
            )
            print("Cause: %s\n\n" % e)
            return 0

    acceptable, compat = compare(master_parsed, current_parsed, options.mode)

    def explain(header, compat):
        print(header)
        # indent compatibility explanation
        print('\n\t'.join(compat.explain().split('\n')))

    if acceptable:
        explain("--- PASS ---", compat)
        if options.force_verification == False:
            print("Updating sha1 to %s" % hexdigest)
            sha_filename = "%s.sha1" % current_filename
            sha_file = open(sha_filename, 'w')
            sha_file.write(hexdigest)
            sha_file.close()
    else:
        explain("*** FAIL ***", compat)
        return 1
Exemplo n.º 6
0
 def parse_master_url():
     master = fetch(master_url)
     return llmessage.parseTemplateString(master)
Exemplo n.º 7
0
def run(sysargs):
    parser = optparse.OptionParser(
        usage="usage: %prog [FILE] [FILE]",
        description=__doc__)
    parser.add_option(
        '-m', '--mode', type='string', dest='mode',
        default='development',
        help="""[development|production] The strictness mode to use
while checking the template; see the wiki page for details about
what is allowed and disallowed by each mode:
http://wiki.secondlife.com/wiki/Template_verifier.py
""")
    parser.add_option(
        '-u', '--master_url', type='string', dest='master_url',
        default='http://secondlife.com/app/message_template/master_message_template.msg',
        help="""The url of the master message template.""")
    parser.add_option(
        '-c', '--cache_master', action='store_true', dest='cache_master',
        default=False,  help="""Set to true to attempt use local cached copy of the master template.""")

    options, args = parser.parse_args(sysargs)

    if options.mode == 'production':
        options.cache_master = False

    # both current and master supplied in positional params
    if len(args) == 2:
        master_filename, current_filename = args
        print "master:", master_filename
        print "current:", current_filename
        master_url = 'file://%s' % master_filename
        current_url = 'file://%s' % current_filename
    # only current supplied in positional param
    elif len(args) == 1:
        master_url = None
        current_filename = args[0]
        print "master:", options.master_url 
        print "current:", current_filename
        current_url = 'file://%s' % current_filename
    # nothing specified, use defaults for everything
    elif len(args) == 0:
        master_url  = None
        current_url = None
    else:
        die("Too many arguments")

    if master_url is None:
        master_url = options.master_url
        
    if current_url is None:
        current_filename = local_template_filename()
        print "master:", options.master_url
        print "current:", current_filename
        current_url = 'file://%s' % current_filename

    # retrieve the contents of the local template and check for syntax
    current = fetch(current_url)
    current_parsed = llmessage.parseTemplateString(current)

    if options.cache_master:
        # optionally return a url to a locally-cached master so we don't hit the network all the time
        master_url = cache_master(master_url)

    def parse_master_url():
        master = fetch(master_url)
        return llmessage.parseTemplateString(master)
    try:
        master_parsed = retry(3, parse_master_url)
    except (IOError, tokenstream.ParseError), e:
        if options.mode == 'production':
            raise e
        else:
            print "WARNING: problems retrieving the master from %s."  % master_url
            print "Syntax-checking the local template ONLY, no compatibility check is being run."
            print "Cause: %s\n\n" % e
            return 0
Exemplo n.º 8
0
 def get_and_test_master():
     new_master_contents = fetch(master_url)
     llmessage.parseTemplateString(new_master_contents)
     return new_master_contents
def run(sysargs):
    parser = optparse.OptionParser(usage="usage: %prog [FILE] [FILE]", description=__doc__)
    parser.add_option(
        "-m",
        "--mode",
        type="string",
        dest="mode",
        default="development",
        help="""[development|production] The strictness mode to use
while checking the template; see the wiki page for details about
what is allowed and disallowed by each mode:
http://wiki.secondlife.com/wiki/Template_verifier.py
""",
    )
    parser.add_option(
        "-u",
        "--master_url",
        type="string",
        dest="master_url",
        default="http://bitbucket.org/lindenlab/master-message-template/raw/tip/message_template.msg",
        help="""The url of the master message template.""",
    )
    parser.add_option(
        "-c",
        "--cache_master",
        action="store_true",
        dest="cache_master",
        default=False,
        help="""Set to true to attempt use local cached copy of the master template.""",
    )
    parser.add_option(
        "-f",
        "--force",
        action="store_true",
        dest="force_verification",
        default=False,
        help="""Set to true to skip the sha_1 check and force template verification.""",
    )

    options, args = parser.parse_args(sysargs)

    if options.mode == "production":
        options.cache_master = False

    # both current and master supplied in positional params
    if len(args) == 2:
        master_filename, current_filename = args
        print "master:", master_filename
        print "current:", current_filename
        master_url = "file://%s" % master_filename
        current_url = "file://%s" % current_filename
    # only current supplied in positional param
    elif len(args) == 1:
        master_url = None
        current_filename = args[0]
        print "master:", options.master_url
        print "current:", current_filename
        current_url = "file://%s" % current_filename
    # nothing specified, use defaults for everything
    elif len(args) == 0:
        master_url = None
        current_url = None
    else:
        die("Too many arguments")

    if master_url is None:
        master_url = options.master_url

    if current_url is None:
        current_filename = local_template_filename()
        print "master:", options.master_url
        print "current:", current_filename
        current_url = "file://%s" % current_filename

    # retrieve the contents of the local template
    current = fetch(current_url)
    hexdigest = hashlib.sha1(current).hexdigest()
    if not options.force_verification:
        # Early exist if the template hasn't changed.
        sha_url = "%s.sha1" % current_url
        current_sha = fetch(sha_url)
        if hexdigest == current_sha:
            print "Message template SHA_1 has not changed."
            sys.exit(0)

    # and check for syntax
    current_parsed = llmessage.parseTemplateString(current)

    if options.cache_master:
        # optionally return a url to a locally-cached master so we don't hit the network all the time
        master_url = cache_master(master_url)

    def parse_master_url():
        master = fetch(master_url)
        return llmessage.parseTemplateString(master)

    try:
        master_parsed = retry(3, parse_master_url)
    except (IOError, tokenstream.ParseError), e:
        if options.mode == "production":
            raise e
        else:
            print "WARNING: problems retrieving the master from %s." % master_url
            print "Syntax-checking the local template ONLY, no compatibility check is being run."
            print "Cause: %s\n\n" % e
            return 0