Ejemplo n.º 1
0
def parse_logfile_info(filename, verbose=False):
    # Open source temp log file.  Let exceptions percolate up.
    sourcefile = open(filename,
                      'rU')  # U is to open with Universal newline support

    if verbose:
        print "Reading " + filename

    # The first line is the meta info line.
    info_line = sourcefile.readline()
    if not info_line:
        sourcefile.close()
        return None

    # The rest of the lines are frames.  Read the first and last to get the time range.
    info = llsd.parse(info_line)
    info['start_time'] = None
    info['end_time'] = None
    first_frame = sourcefile.readline()
    if first_frame:
        try:
            info['start_time'] = int(llsd.parse(first_frame)['timestamp'])
        except:
            pass

    # Read the file backwards to find the last two lines.
    sourcefile.seek(0, 2)
    file_size = sourcefile.tell()
    offset = 1024
    num_attempts = 0
    end_time = None
    if file_size < offset:
        offset = file_size
    while 1:
        sourcefile.seek(-1 * offset, 2)
        read_str = sourcefile.read(offset)
        # Remove newline at the end
        if read_str[offset - 1] == '\n':
            read_str = read_str[0:-1]
        lines = read_str.split('\n')
        full_line = None
        if len(lines) > 2:  # Got two line
            try:
                end_time = llsd.parse(lines[-1])['timestamp']
            except:
                # We couldn't parse this line.  Try once more.
                try:
                    end_time = llsd.parse(lines[-2])['timestamp']
                except:
                    # Nope.  Just move on.
                    pass
            break
        if len(read_str) == file_size:  # Reached the beginning
            break
        offset += 1024

    info['end_time'] = int(end_time)

    sourcefile.close()
    return info
Ejemplo n.º 2
0
def parse_logfile_info(filename, verbose=False):
    # Open source temp log file.  Let exceptions percolate up.
    sourcefile = open(filename, 'rU') # U is to open with Universal newline support
        
    if verbose:
        print "Reading " + filename  

    # The first line is the meta info line.
    info_line = sourcefile.readline()
    if not info_line:
        sourcefile.close()
        return None

    # The rest of the lines are frames.  Read the first and last to get the time range.
    info = llsd.parse( info_line )
    info['start_time'] = None
    info['end_time'] = None
    first_frame = sourcefile.readline()
    if first_frame:
        try:
            info['start_time'] = int(llsd.parse(first_frame)['timestamp'])
        except:
            pass

    # Read the file backwards to find the last two lines.
    sourcefile.seek(0, 2)
    file_size = sourcefile.tell()
    offset = 1024
    num_attempts = 0
    end_time = None
    if file_size < offset:
        offset = file_size
    while 1:
        sourcefile.seek(-1*offset, 2)
        read_str = sourcefile.read(offset)
        # Remove newline at the end
        if read_str[offset - 1] == '\n':
            read_str = read_str[0:-1]
        lines = read_str.split('\n')
        full_line = None
        if len(lines) > 2:  # Got two line
            try:
                end_time = llsd.parse(lines[-1])['timestamp']
            except:
                # We couldn't parse this line.  Try once more.
                try:
                    end_time = llsd.parse(lines[-2])['timestamp']
                except:
                    # Nope.  Just move on.
                    pass
            break
        if len(read_str) == file_size:   # Reached the beginning
            break
        offset += 1024

    info['end_time'] = int(end_time)

    sourcefile.close()
    return info
Ejemplo n.º 3
0
 def __repr__(self):
     try:
         import simplejson
         traceback = simplejson.loads(self.params.response_body)
     except:
         try:
             from indra.base import llsd
             traceback = llsd.parse(self.params.response_body)
         except:
             traceback = self.params.response_body
     if (isinstance(traceback, dict) and 'stack-trace' in traceback
             and 'description' in traceback):
         body = traceback
         traceback = "Traceback (most recent call last):\n"
         for frame in body['stack-trace']:
             traceback += '  File "%s", line %s, in %s\n' % (
                 frame['filename'], frame['lineno'], frame['method'])
             for line in frame['code']:
                 if line['lineno'] == frame['lineno']:
                     traceback += '    %s' % (line['line'].lstrip(), )
                     break
         traceback += body['description']
     return "The server raised an exception from our request:\n%s %s\n%s %s\n%s" % (
         self.params.method, self.params.url, self.params.response.status,
         self.params.response.reason, traceback)
Ejemplo n.º 4
0
 def __repr__(self):
     try:
         import simplejson
         traceback = simplejson.loads(self.params.response_body)
     except:
         try:
             from indra.base import llsd
             traceback = llsd.parse(self.params.response_body)
         except:
             traceback = self.params.response_body
     if(isinstance(traceback, dict)
         and 'stack-trace' in traceback
         and 'description' in traceback):
         body = traceback
         traceback = "Traceback (most recent call last):\n"
         for frame in body['stack-trace']:
             traceback += '  File "%s", line %s, in %s\n' % (
                 frame['filename'], frame['lineno'], frame['method'])
             for line in frame['code']:
                 if line['lineno'] == frame['lineno']:
                     traceback += '    %s' % (line['line'].lstrip(), )
                     break
         traceback += body['description']
     return "The server raised an exception from our request:\n%s %s\n%s %s\n%s" % (
         self.params.method, self.params.url, self.params.response.status, self.params.response.reason, traceback)
Ejemplo n.º 5
0
def get_channel(version_type):
    if version_type == 'viewer':
        settings_file = open(os.path.join(
            get_src_root(), 'indra', 'newview', 'app_settings', 'settings.xml'))
        data = llsd.parse(settings_file.read())
        settings_file.close()
        return data['VersionChannelName']['Value']
    
    config.load()
    return config.get('channel', 'Second Life Server')
Ejemplo n.º 6
0
def get_channel(version_type):
    if version_type == 'viewer':
        settings_file = open(
            os.path.join(get_src_root(), 'indra', 'newview', 'app_settings',
                         'settings.xml'))
        data = llsd.parse(settings_file.read())
        settings_file.close()
        return data['VersionChannelName']['Value']

    config.load()
    return config.get('channel', 'Second Life Server')
Ejemplo n.º 7
0
 def load_contents(self):
     """ Loads and parses the named query file into self.  Does
     nothing if self.location is nonexistant."""
     if self._location:
         if isinstance(self._location, (str, unicode)):
             contents = llsd.parse(open(self._location).read())
         else:
             # we probably have a file-like object. Godspeed!
             contents = llsd.parse(self._location.read())
         self._reference_contents(contents)
         # Check for alternative implementations
         try:
             for name, alt in self._contents["alternative"].items():
                 nq = NamedQuery(name, None)
                 nq._reference_contents(alt)
                 self._alternative[name] = nq
         except KeyError, e:
             pass
         self._last_mod_time = self.get_modtime()
         self._last_check_time = time.time()
Ejemplo n.º 8
0
    def _load(self):
        if self._indra_config_file is None:
            return

        config_file = open(self._indra_config_file)
        self._config_file_dict = llsd.parse(config_file.read())
        self._combine_dictionaries()
        config_file.close()

        self._last_mod_time = self._get_last_modified_time()
        self._last_check_time = time.time() # now
Ejemplo n.º 9
0
 def load_contents(self):
     """ Loads and parses the named query file into self.  Does
     nothing if self.location is nonexistant."""
     if self._location:
         if isinstance(self._location, (str, unicode)):
             contents = llsd.parse(open(self._location).read())
         else:
             # we probably have a file-like object. Godspeed!
             contents = llsd.parse(self._location.read())
         self._reference_contents(contents)
         # Check for alternative implementations
         try:
             for name, alt in self._contents['alternative'].items():
                 nq = NamedQuery(name, None)
                 nq._reference_contents(alt)
                 self._alternative[name] = nq
         except KeyError, e:
             pass
         self._last_mod_time = self.get_modtime()
         self._last_check_time = time.time()
Ejemplo n.º 10
0
    def _load(self):
        if self._indra_config_file is None:
            return

        config_file = open(self._indra_config_file)
        self._config_file_dict = llsd.parse(config_file.read())
        self._combine_dictionaries()
        config_file.close()

        self._last_mod_time = self._get_last_modified_time()
        self._last_check_time = time.time()  # now
Ejemplo n.º 11
0
 def load(self):
     if os.path.exists(self._install_filename):
         install = llsd.parse(file(self._install_filename, "rb").read())
         try:
             for name in install["installables"]:
                 self._installables[name] = InstallableDefinition(install["installables"][name])
         except KeyError:
             pass
         try:
             for name in install["licenses"]:
                 self._licenses[name] = LicenseDefinition(install["licenses"][name])
         except KeyError:
             pass
     if os.path.exists(self._installed_filename):
         installed = llsd.parse(file(self._installed_filename, "rb").read())
         try:
             bins = installed["installables"]
             for name in bins:
                 self._installed[name] = InstalledPackage(bins[name])
         except KeyError:
             pass
Ejemplo n.º 12
0
    def _load(self):
        # if you initialize the IndraConfig with None, no attempt
        # is made to load any files
        if self._indra_config_file is None:
            return

        config_file = open(self._indra_config_file)
        self._config_file_dict = llsd.parse(config_file.read())
        self._combine_dictionaries()
        config_file.close()

        self._last_mod_time = self._get_last_modified_time()
        self._last_check_time = time.time()  # now
Ejemplo n.º 13
0
 def load(self):
     if os.path.exists(self._install_filename):
         install = llsd.parse(file(self._install_filename, 'rb').read())
         try:
             for name in install['installables']:
                 self._installables[name] = InstallableDefinition(
                     install['installables'][name])
         except KeyError:
             pass
         try:
             for name in install['licenses']:
                 self._licenses[name] = LicenseDefinition(install['licenses'][name])
         except KeyError:
             pass
     if os.path.exists(self._installed_filename):
         installed = llsd.parse(file(self._installed_filename, 'rb').read())
         try:
             bins = installed['installables']
             for name in bins:
                 self._installed[name] = InstalledPackage(bins[name])
         except KeyError:
             pass
Ejemplo n.º 14
0
    def _load(self):
        # if you initialize the IndraConfig with None, no attempt
        # is made to load any files
        if self._indra_config_file is None:
            return

        config_file = open(self._indra_config_file)
        self._config_file_dict = llsd.parse(config_file.read())
        self._combine_dictionaries()
        config_file.close()

        self._last_mod_time = self._get_last_modified_time()
        self._last_check_time = time.time() # now
Ejemplo n.º 15
0
 def load_contents(self):
     """ Loads and parses the named query file into self.  Does
     nothing if self.location is nonexistant."""
     if self._location:
         self._reference_contents(llsd.parse(open(self._location).read()))
         # Check for alternative implementations
         try:
             for name, alt in self._contents['alternative'].items():
                 nq = NamedQuery(name, None)
                 nq._reference_contents(alt)
                 self._alternative[name] = nq
         except KeyError, e:
             pass
         self._last_mod_time = self.get_modtime()
         self._last_check_time = time.time()
Ejemplo n.º 16
0
 def load_contents(self):
     """ Loads and parses the named query file into self.  Does
     nothing if self.location is nonexistant."""
     if self._location:
         self._reference_contents(llsd.parse(open(self._location).read()))
         # Check for alternative implementations
         try:
             for name, alt in self._contents['alternative'].items():
                 nq = NamedQuery(name, None)
                 nq._reference_contents(alt)
                 self._alternative[name] = nq
         except KeyError, e:
             pass
         self._last_mod_time = self.get_modtime()
         self._last_check_time = time.time()
Ejemplo n.º 17
0
    def update(self, new_conf):
        """
        Load an XML file and apply its map as overrides or additions
        to the existing config.  Update can be a file or a dict.

        Once any key/value pair is changed via the update method,
        that key/value pair will remain set with that value until
        change via the update or set method
        """
        if isinstance(new_conf, dict):
            overrides = new_conf
        else:
            # assuming that it is a filename
            config_file = open(new_conf)
            overrides = llsd.parse(config_file.read())
            config_file.close()
  
        self._config_overrides.update(overrides)
        self._combine_dictionaries()
Ejemplo n.º 18
0
    def update(self, new_conf):
        """
        Load an XML file and apply its map as overrides or additions
        to the existing config.  Update can be a file or a dict.

        Once any key/value pair is changed via the update method,
        that key/value pair will remain set with that value until
        change via the update or set method
        """
        if isinstance(new_conf, dict):
            overrides = new_conf
        else:
            # assuming that it is a filename
            config_file = open(new_conf)
            overrides = llsd.parse(config_file.read())
            config_file.close()

        self._config_overrides.update(overrides)
        self._combine_dictionaries()
Ejemplo n.º 19
0
    def init_testing( self ):
        global gIsLoggingEnabled

        host_performance_file = "/dev/shm/simperf/simperf_proc_config.llsd"
    
        #If file exists, open
        if os.path.exists(host_performance_file):
            file = open (host_performance_file,'r')
    
            #Read serialized LLSD from file.
            body = llsd.parse(file.read())
    
            #Calculate time since file last modified.
            stats = os.stat(host_performance_file)
            now = time.time()
            mod = stats[stat.ST_MTIME]
            age = now - mod
    
            if age < ( body['duration'] ):
                gIsLoggingEnabled = True
Ejemplo n.º 20
0
    def init_testing(self):
        global gIsLoggingEnabled

        host_performance_file = "/dev/shm/simperf/simperf_proc_config.llsd"

        #If file exists, open
        if os.path.exists(host_performance_file):
            file = open(host_performance_file, 'r')

            #Read serialized LLSD from file.
            body = llsd.parse(file.read())

            #Calculate time since file last modified.
            stats = os.stat(host_performance_file)
            now = time.time()
            mod = stats[stat.ST_MTIME]
            age = now - mod

            if age < (body['duration']):
                gIsLoggingEnabled = True
Ejemplo n.º 21
0
def parse_logfile(filename, target_column=None, verbose=False):
    full_doc = []
    # Open source temp log file.  Let exceptions percolate up.
    sourcefile = open(filename, 'r')

    if verbose:
        print "Reading " + filename

    # Parse and output all lines from the temp file
    for line in sourcefile.xreadlines():
        partial_doc = llsd.parse(line)
        if partial_doc is not None:
            if target_column is None:
                full_doc.append(partial_doc)
            else:
                trim_doc = {target_column: partial_doc[target_column]}
                if target_column != "fps":
                    trim_doc['fps'] = partial_doc['fps']
                trim_doc['/total_time'] = partial_doc['/total_time']
                trim_doc['utc_time'] = partial_doc['utc_time']
                full_doc.append(trim_doc)

    sourcefile.close()
    return full_doc
Ejemplo n.º 22
0
def parse_logfile(filename, target_column=None, verbose=False):
    full_doc = []
    # Open source temp log file.  Let exceptions percolate up.
    sourcefile = open( filename,'r')
        
    if verbose:
        print "Reading " + filename  
    
    # Parse and output all lines from the temp file
    for line in sourcefile.xreadlines():
        partial_doc = llsd.parse(line)
        if partial_doc is not None:
            if target_column is None:
                full_doc.append(partial_doc)
            else:
                trim_doc = { target_column: partial_doc[target_column] }
                if target_column != "fps":
                    trim_doc[ 'fps' ] = partial_doc[ 'fps' ]
                trim_doc[ '/total_time' ] = partial_doc[ '/total_time' ]
                trim_doc[ 'utc_time' ] = partial_doc[ 'utc_time' ]
                full_doc.append(trim_doc)

    sourcefile.close()
    return full_doc
Ejemplo n.º 23
0
def postFile(url, filename):
    f = open(filename)
    body = f.read()
    f.close()
    llsd_body = llsd.parse(body)
    return post_(url, llsd_body)
Ejemplo n.º 24
0
 def read_xml(self):
     # This approach reads the entire POST data into memory first
     return llsd.parse(self.read())
Ejemplo n.º 25
0
def postFile(url, filename, verbose=False):
    f = open(filename)
    body = f.read()
    f.close()
    llsd_body = llsd.parse(body)
    return post(url, llsd_body, verbose=verbose)
 def read_xml(self):
     # This approach reads the entire POST data into memory first
     return llsd.parse(self.read())
Ejemplo n.º 27
0
def postFile(url, filename):
    f = open(filename)
    body = f.read()
    f.close()
    llsd_body = llsd.parse(body)
    return post_(url, llsd_body)
Ejemplo n.º 28
0
def main():
    options, args = parse_args()
    installer = Installer(
        options.install_filename,
        options.installed_filename,
        options.dryrun)

    #
    # Handle the queries for information
    #
    if options.list_installed:
        print "installed list:", installer.list_installed()
        return 0
    if options.list_installables:
        print "installable list:", installer.list_installables()
        return 0
    if options.detail_installable:
        try:
            detail = installer.detail_installable(options.detail_installable)
            print "Detail on installable",options.detail_installable+":"
            pprint.pprint(detail)
        except KeyError:
            print "Installable '"+options.detail_installable+"' not found in",
            print "install file."
        return 0
    if options.detail_installed:
        try:
            detail = installer.detail_installed(options.detail_installed)
            #print "Detail on installed",options.detail_installed+":"
            for line in detail:
                print line
        except:
            raise
            print "Installable '"+options.detail_installed+"' not found in ",
            print "install file."
        return 0
    if options.list_licenses:
        print "license list:", installer.list_licenses()
        return 0
    if options.detail_license:
        try:
            detail = installer.detail_license(options.detail_license)
            print "Detail on license",options.detail_license+":"
            pprint.pprint(detail)
        except KeyError:
            print "License '"+options.detail_license+"' not defined in",
            print "install file."
        return 0
    if options.export_manifest:
        # *HACK: just re-parse the install manifest and pretty print
        # it. easier than looking at the datastructure designed for
        # actually determining what to install
        install = llsd.parse(file(options.install_filename, 'rb').read())
        pprint.pprint(install)
        return 0

    #
    # Handle updates -- can only do one of these
    # *TODO: should this change the command line syntax?
    #
    if options.new_license:
        if not installer.add_license(
            options.new_license,
            text=options.license_text,
            url=options.license_url):
            return 1
    elif options.remove_license:
        installer.remove_license(options.remove_license)
    elif options.remove_installable:
        installer.remove_installable(options.remove_installable)
    elif options.add_installable:
        if not installer.add_installable(
            options.add_installable,
            copyright=options.installable_copyright,
            license=options.installable_license,
            description=options.installable_description,
            platform=options.package_platform,
            url=options.package_url,
            md5sum=options.package_md5):
            return 1
    elif options.add_installable_metadata:
        if not installer.add_installable_metadata(
            options.add_installable_metadata,
            copyright=options.installable_copyright,
            license=options.installable_license,
            description=options.installable_description):
            return 1
    elif options.add_installable_package:
        if not installer.add_installable_package(
            options.add_installable_package,
            platform=options.package_platform,
            url=options.package_url,
            md5sum=options.package_md5):
            return 1
    elif options.uninstall:
        installer.do_uninstall(args, options.install_dir)
    else:
        installer.do_install(args, options.platform, options.install_dir, 
                             options.cache_dir, options.check_license, 
                             options.scp) 

    # save out any changes
    installer.save()
    return 0
Ejemplo n.º 29
0
def main():
    options, args = parse_args()
    installer = Installer(
        options.install_filename,
        options.installed_filename,
        options.dryrun)

    #
    # Handle the queries for information
    #
    if options.sort_manifest:
        installer.sort()
        return 0
    if options.list_installed:
        print "installed list:", installer.list_installed()
        return 0
    if options.list_installables:
        print "installable list:", installer.list_installables()
        return 0
    if options.detail_installable:
        try:
            detail = installer.detail_installable(options.detail_installable)
            print "Detail on installable",options.detail_installable+":"
            pprint.pprint(detail)
        except KeyError:
            print "Installable '"+options.detail_installable+"' not found in",
            print "install file."
        return 0
    if options.detail_installed:
        try:
            detail = installer.detail_installed(options.detail_installed)
            #print "Detail on installed",options.detail_installed+":"
            for line in detail:
                print line
        except:
            raise
            print "Installable '"+options.detail_installed+"' not found in ",
            print "install file."
        return 0
    if options.list_licenses:
        print "license list:", installer.list_licenses()
        return 0
    if options.detail_license:
        try:
            detail = installer.detail_license(options.detail_license)
            print "Detail on license",options.detail_license+":"
            pprint.pprint(detail)
        except KeyError:
            print "License '"+options.detail_license+"' not defined in",
            print "install file."
        return 0
    if options.export_manifest:
        # *HACK: just re-parse the install manifest and pretty print
        # it. easier than looking at the datastructure designed for
        # actually determining what to install
        install = llsd.parse(file(options.install_filename, 'rb').read())
        pprint.pprint(install)
        return 0

    #
    # Handle updates -- can only do one of these
    # *TODO: should this change the command line syntax?
    #
    if options.new_license:
        if not installer.add_license(
            options.new_license,
            text=options.license_text,
            url=options.license_url):
            return 1
    elif options.remove_license:
        installer.remove_license(options.remove_license)
    elif options.remove_installable:
        installer.remove_installable(options.remove_installable)
    elif options.add_installable:
        if not installer.add_installable(
            options.add_installable,
            copyright=options.installable_copyright,
            license=options.installable_license,
            description=options.installable_description,
            platform=options.package_platform,
            url=options.package_url,
            md5sum=options.package_md5):
            return 1
    elif options.add_installable_metadata:
        if not installer.add_installable_metadata(
            options.add_installable_metadata,
            copyright=options.installable_copyright,
            license=options.installable_license,
            description=options.installable_description):
            return 1
    elif options.add_installable_package:
        if not installer.add_installable_package(
            options.add_installable_package,
            platform=options.package_platform,
            url=options.package_url,
            md5sum=options.package_md5):
            return 1
    elif options.uninstall:
        installer.do_uninstall(args, options.install_dir)
    else:
        installer.do_install(args, options.platform, options.install_dir, 
                             options.cache_dir, options.check_license, 
                             options.scp) 

    # save out any changes
    installer.save()
    return 0
Ejemplo n.º 30
0
 def load(self):
     self.stuff = llsd.parse(file(self._filename, 'rb').read())
Ejemplo n.º 31
0
    def rez(self, agent):
        """rez an IAgent on that region"""

        session_id = str(uuid.uuid1())
        secure_session_id = session_id
        circuit_code = random.randint(0, 9999999)
        data = {
            'agent_id': agent.agent_id,
            'first_name': agent.first_name,
            'last_name': agent.last_name,
            'age_verified': agent.age_verified,
            'agent_access': agent.agent_access,
            'allow_redirect': agent.allow_redirect,
            'god_level': agent.god_level,
            'identified': agent.identified,
            'transacted': agent.transacted,
            'limited_to_estate': agent.limited_to_estate,
            'sim_access': agent.sim_access
        }
        xml = llsd.format_xml(data)

        url = urljoin(self.url, 'agent/%s/request' % agent.agent_id)
        headers = {
            'Content-Type': 'application/llsd+xml',
            'Content-Length': len(xml)
        }
        request = urllib2.Request(url, xml, headers)
        result = urllib2.urlopen(request).read()

        result = llsd.parse(result)
        # TODO: Error handling! What are the possible error conditions?

        # step two: rez_avatar
        url = result['rez_avatar/rez']

        # create the rez_avatar payload:
        data = {
            'first_name': agent.first_name,
            'last_name': agent.last_name,
            'secure_session_id': session_id,
            'age_verified': False,
            'region_id': '00000000-0000-0000-0000-000000000000',
            'transacted': False,
            'agent_access': False,
            'circuit_code': circuit_code,
            'identified': False,
            'session_id': session_id,
            'god_level': 0,
            'god_override': False,
            'inventory_host': 'inv4.mysql.agni.lindenlab.com',
            'limited_to_estate': '1',
            'position': self.position,
            'start': 'safe'
        }

        xml = llsd.format_xml(data)
        headers = {
            'Content-Type': 'application/llsd+xml',
            'Content-Length': len(xml)
        }
        request = urllib2.Request(url, xml, headers)
        result = urllib2.urlopen(request).read()

        data = llsd.parse(result)

        self.region_y = data.get('region_y', None)
        self.region_x = data.get('region_x', None)
        self.seed_capability = data.get('seed_capability', None)
        self.region_id = data.get('region_id', None)
        self.sim_access = data.get('sim_access', None)
        self.connect = data.get('connect', None)
        self.sim_port = data.get('sim_port', None)
        self.sim_ip = data.get('sim_ip', None)
        self.session_id = session_id
        self.secure_session_id = secure_session_id
        self.circuit_code = circuit_code
        self.agent_id = agent.agent_id
Ejemplo n.º 32
0
 def load(self):
     self.stuff = llsd.parse(file(self._filename, 'rb').read())