Пример #1
0
    def __init__(self, edrserver, edrinara):
        self.server = edrserver
        self.inara = edrinara
        self._player = EDCmdr()
        self.heartbeat_timestamp = None

        edr_config = edrconfig.EDRConfig()
        self._edr_heartbeat = edr_config.edr_heartbeat()

        try:
            with open(self.EDR_CMDRS_CACHE, 'rb') as handle:
                self.cmdrs_cache = pickle.load(handle)
        except:
            self.cmdrs_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                 edr_config.cmdrs_max_age())

        try:
            with open(self.EDR_INARA_CACHE, 'rb') as handle:
                self.inara_cache = pickle.load(handle)
        except:
            self.inara_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                 edr_config.inara_max_age())

        try:
            with open(self.EDR_SQDRDEX_CACHE, 'rb') as handle:
                self.sqdrdex_cache = pickle.load(handle)
        except:
            self.sqdrdex_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.sqdrdex_max_age())
Пример #2
0
    def __init__(self):
        edr_config = edrconfig.EDRConfig()
        set_language(config.get("language"))

        self.edr_version = edr_config.edr_version()
        EDRLOG.log(u"Version {}".format(self.edr_version), "INFO")

        self.system_novelty_threshold = edr_config.system_novelty_threshold()
        self.place_novelty_threshold = edr_config.place_novelty_threshold()
        self.ship_novelty_threshold = edr_config.ship_novelty_threshold()
        self.cognitive_novelty_threshold = edr_config.cognitive_novelty_threshold(
        )
        self.intel_even_if_clean = edr_config.intel_even_if_clean()

        self.edr_needs_u_novelty_threshold = edr_config.edr_needs_u_novelty_threshold(
        )
        self.previous_ad = None

        self.blips_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                             edr_config.blips_max_age())
        self.cognitive_blips_cache = lrucache.LRUCache(
            edr_config.lru_max_size(), edr_config.blips_max_age())
        self.traffic_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                               edr_config.traffic_max_age())
        self.scans_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                             edr_config.scans_max_age())
        self.cognitive_scans_cache = lrucache.LRUCache(
            edr_config.lru_max_size(), edr_config.blips_max_age())

        self._email = tk.StringVar(value=config.get("EDREmail"))
        self._password = tk.StringVar(value=config.get("EDRPassword"))
        # Translators: this is shown on the EDMC's status line
        self._status = tk.StringVar(value=_(u"not authenticated."))
        self.status_ui = None

        visual = 1 if config.get("EDRVisualFeedback") == "True" else 0
        self._visual_feedback = tk.IntVar(value=visual)

        audio = 1 if config.get("EDRAudioFeedback") == "True" else 0
        self._audio_feedback = tk.IntVar(value=audio)

        self.player = edentities.EDCmdr()
        self.server = edrserver.EDRServer()

        self.edrsystems = edrsystems.EDRSystems(self.server)
        self.edrcmdrs = edrcmdrs.EDRCmdrs(self.server)
        self.edroutlaws = edroutlaws.EDROutlaws(self.server)
        self.edrlegal = edrlegalrecords.EDRLegalRecords(self.server)

        self.mandatory_update = False
        self.crimes_reporting = True
        self.motd = []
        self.tips = randomtips.RandomTips()
        self.help_content = helpcontent.HelpContent()
Пример #3
0
    def __init__(self, server, opponent_kind, client_callback):
        self.server = server
        self.kind = opponent_kind
        self.powerplay = None
        self.realtime_callback = client_callback
        self.realtime = None

        config = edrconfig.EDRConfig()
        try:
            with open(self.EDR_OPPONENTS_SIGHTINGS_CACHES[opponent_kind],
                      'rb') as handle:
                self.sightings = pickle.load(handle)
        except:
            self.sightings = lrucache.LRUCache(
                config.lru_max_size(), config.opponents_max_age(self.kind))

        try:
            with open(self.EDR_OPPONENTS_RECENTS_CACHES[opponent_kind],
                      'rb') as handle:
                self.recents = pickle.load(handle)
        except:
            self.recents = deque(
                maxlen=config.opponents_max_recents(self.kind))

        self.timespan = config.opponents_recent_threshold(self.kind)
        self.reports_check_interval = config.reports_check_interval()
def procesar(path, tam, warm, test):
	print "Leyendo el archivos de queries y procesando"
	cache = lrucache.LRUCache(tam)	#Declaro el cache LRU con un tamaño dado
	try:
		archivo = open (path, "r")
	except e:
		print "Error de lectura: " + e
		
	query = archivo.readline()	#leo la primer linea
	if warm != 0:
		#Si el calentamiento es mayor a 0, hay calentamiento
		cW = 1 #contador de calentamiento
		while (query != '') and (cW < int(warm)):
			#Mientras no sea linea vacia o Mientras no haya terminado el calentamiento
			cache.accessPage(query.strip(), False) #Cacheo pero no hago el recuento de hit, porque es calentamiento
			cW += 1 #Sumo el contador de calentamiento
			query = archivo.readline()	#leo otra linea
	cQ = 1	#Contador de queries leidas
	while (query != '') and (cQ <= test):
		cache.accessPage(query.strip(), True) #Cacheo y hago el recuento de hit
		cQ += 1 #Contador de queries
		query = archivo.readline()	#leo otra linea
	
	print "Proceso terminado"
	archivo.close()
	hit = cache.getTotalHit()
	return hit
Пример #5
0
 def __init__(self, MapServ_inst, configpath):
     TilesRepository.__init__(self, MapServ_inst, configpath)
     self.set_repository_path(configpath)
     self.tile_cache = lrucache.LRUCache(1000)
     self.mapServ_inst = MapServ_inst
     self.lock = Lock()
     self.missingPixbuf = mapPixbuf.missing()
Пример #6
0
 def __init__(self):
     self._overlay = edmcoverlay.Overlay()
     self.cfg = {}
     self.general_config()
     self.must_clear = False
     for kind in self.MESSAGE_KINDS:
         self.message_config(kind)
     self.msg_ids = lrucache.LRUCache(1000, 60 * 15)
    def __init__(self, MapServ_inst, configpath):
        TilesRepository.__init__(self, MapServ_inst, configpath)
        self.tile_cache = lrucache.LRUCache(1000)
        self.mapServ_inst = MapServ_inst
        self.configpath = configpath
        self.lock = Lock()

        self.missingPixbuf = mapPixbuf.missing()

        self.sqlite3func = SQLite3Funcs( self.configpath, SQLITE3_REPOSITORY_FILE )
Пример #8
0
 def pledged_to(self, power, time_pledged):
     if self.kind is not EDROpponents.ENEMIES:
         return
     if not power or self.powerplay is not power:
         config = edrconfig.EDRConfig()
         self.recents = deque(
             maxlen=config.opponents_max_recents(self.kind))
         self.sightings = lrucache.LRUCache(
             config.lru_max_size(), config.opponents_max_age(self.kind))
     self.powerplay = power
Пример #9
0
    def __init__(self, server):
        self.server = server
        self.inara = edrinara.EDRInara()

        edr_config = edrconfig.EDRConfig()

        try:
            with open(self.EDR_CMDRS_CACHE, 'rb') as handle:
                self.cmdrs_cache = pickle.load(handle)
        except:
            self.cmdrs_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                 edr_config.cmdrs_max_age())

        try:
            with open(self.EDR_INARA_CACHE, 'rb') as handle:
                self.inara_cache = pickle.load(handle)
        except:
            self.inara_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                 edr_config.inara_max_age())
Пример #10
0
    def __init__(self, server):
        edr_config = edrconfig.EDRConfig()

        try:
            with open(self.EDR_SYSTEMS_CACHE, 'rb') as handle:
                self.systems_cache = pickle.load(handle)
        except:
            self.systems_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                   edr_config.systems_max_age())

        try:
            with open(self.EDR_NOTAMS_CACHE, 'rb') as handle:
                self.notams_cache = pickle.load(handle)
        except:
            self.notams_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.notams_max_age())

        try:
            with open(self.EDR_SITREPS_CACHE, 'rb') as handle:
                self.sitreps_cache = pickle.load(handle)
        except:
            self.sitreps_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.sitreps_max_age())

        try:
            with open(self.EDR_CRIMES_CACHE, 'rb') as handle:
                self.crimes_cache = pickle.load(handle)
        except:
            self.crimes_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.crimes_max_age())

        try:
            with open(self.EDR_TRAFFIC_CACHE, 'rb') as handle:
                self.traffic_cache = pickle.load(handle)
        except:
            self.traffic_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.traffic_max_age())


        self.reports_check_interval = edr_config.reports_check_interval()
        self.notams_check_interval = edr_config.notams_check_interval()
        self.timespan = edr_config.sitreps_timespan()
        self.server = server
Пример #11
0
 def CreateConnection(self, request: chat.User, context):
     users = [request.name, request.othername]
     self.requestFromUser[request.othername] = chat.User(name=request.name)
     users.sort()
     new_key = users[0] + "-" + users[1]
     
     for online_user in self.registeredUsers:
         if (online_user.name == request.othername):
             if new_key not in self.messages:
                 self.messages[new_key] = lrucache.LRUCache(max_num_messages)
             return chat.Connection(successful=True)
     return chat.Connection(successful=False)
Пример #12
0
    def __init__(self, server):
        self.server = server

        self.timespan = None
        self.records_last_updated = None
        self.records_check_interval = None
        config = edrconfig.EDRConfig()
        try:
            with open(self.EDR_LEGAL_RECORDS_CACHE, 'rb') as handle:
                self.records = pickle.load(handle)
        except:
            self.records = lrucache.LRUCache(config.lru_max_size(),
                                             config.legal_records_max_age())

        self.timespan = config.legal_records_recent_threshold()
        self.reports_check_interval = config.legal_records_check_interval()
Пример #13
0
 def message_config(self, kind):
     conf = igmconfig.IGMConfig()
     self.cfg[kind] = {
         "h": {
             "x": conf.x(kind, "header"),
             "y": conf.y(kind, "header"),
             "ttl": conf.ttl(kind, "header"),
             "rgb": conf.rgb(kind, "header"),
             "size": conf.size(kind, "header"),
             "len": conf.len(kind, "header"),
             "align": conf.align(kind, "header")
         },
         "b": {
             "x":
             conf.x(kind, "body"),
             "y":
             conf.y(kind, "body"),
             "ttl":
             conf.ttl(kind, "body"),
             "rgb":
             conf.rgb(kind, "body"),
             "size":
             conf.size(kind, "body"),
             "len":
             conf.len(kind, "body"),
             "align":
             conf.align(kind, "body"),
             "rows":
             conf.body_rows(kind),
             "cache":
             lrucache.LRUCache(conf.body_rows(kind), conf.ttl(kind,
                                                              "body")),
             "last_row":
             0
         }
     }
     if not conf.panel(kind):
         return
     self.cfg[kind]["panel"] = {
         "x": conf.x(kind, "panel"),
         "y": conf.y(kind, "panel"),
         "x2": conf.x2(kind, "panel"),
         "y2": conf.y2(kind, "panel"),
         "ttl": conf.ttl(kind, "panel"),
         "rgb": conf.rgb(kind, "panel"),
         "fill": conf.fill(kind, "panel")
     }
Пример #14
0
    def __init__(self, server):
        self.server = server
        config = edrconfig.EDRConfig()
        try:
            with open(self.EDR_OUTLAWS_SIGHTINGS_CACHE, 'rb') as handle:
                self.sightings = pickle.load(handle)
        except:
            self.sightings = lrucache.LRUCache(config.lru_max_size(), config.outlaws_max_age())

        try:
            with open(self.EDR_OUTLAWS_RECENTS_CACHE, 'rb') as handle:
                self.recents = pickle.load(handle)
        except:
            self.recents = deque(maxlen=config.outlaws_max_recents())

        self.timespan = config.outlaws_recent_threshold()
        self.reports_check_interval = config.reports_check_interval()
Пример #15
0
class CacheWrapper:  # this is kind of a weakref proxy, but hashable
    # TODO put that refs in the context
    refs = lrucache.LRUCache(5000)

    # duh, it works ! TODO: .saveme() on cache eviction
    # but there is no memory reduction as the GC does not collect that shit.
    # i would guess too many fields, map, context...
    def __init__(self, context, addr):
        self._addr = addr
        self._fname = makeFilenameFromAddr(context, addr)
        if not os.access(self._fname, os.F_OK):
            raise ValueError()
        self._context = context
        self.obj = None

    def __getattr__(self, *args):
        if self.obj is None or self.obj() is None:  #
            self._load()
        return getattr(self.obj(), *args)

    def unload(self):
        if self._addr in CacheWrapper.refs:
            del CacheWrapper.refs[self._addr]
        self.obj = None

    def _load(self):
        if self.obj is not None:  #
            if self.obj() is not None:  #
                return self.obj()
        try:
            p = pickle.load(file(self._fname, 'r'))
        except EOFError, e:
            log.error('Could not load %s - removing it ' % (self._fname))
            os.remove(self._fname)
            raise e
        if not isinstance(p, AnonymousStructInstance):
            raise EOFError('not a AnonymousStructInstance in cache. %s' %
                           (p.__class__))
        p.setContext(self._context)
        p._dirty = False
        CacheWrapper.refs[self._addr] = p
        self.obj = weakref.ref(p)
        return
Пример #16
0
class CacheWrapper:
    """
    this is kind of a weakref proxy, but hashable
    """
    # TODO put that refs in the context
    refs = lrucache.LRUCache(5000)
    # duh, it works ! TODO: .saveme() on cache eviction
    # but there is no memory reduction as the GC does not collect that shit.
    # i would guess too many fields, map, context...

    def __init__(self, _context, address):
        self.address = address
        self._fname = make_filename_from_addr(_context, address)
        if not os.access(self._fname, os.F_OK):
            raise ValueError("%s does not exists" % self._fname)
        self._memory_handler = _context.memory_handler
        self.obj = None

    def __getattr__(self, *args):
        if self.obj is None or self.obj() is None:  #
            self._load()
        return getattr(self.obj(), *args)

    def unload(self):
        if self.address in CacheWrapper.refs:
            del CacheWrapper.refs[self.address]
        self.obj = None

    def _load(self):
        if self.obj is not None:  #
            if self.obj() is not None:  #
                return self.obj()
        try:
            p = pickle.load(file(self._fname, 'r'))
        except EOFError as e:
            log.error('Could not load %s - removing it %s', self._fname, e)
            os.remove(self._fname)
            raise e  # bad file removed
        if not isinstance(p, AnonymousRecord):
            raise EOFError("not a AnonymousRecord in cache. %s", p.__class__)
        if isinstance(p, CacheWrapper):
            raise TypeError("Why is a cache wrapper pickled?")
        p.set_memory_handler(self._memory_handler)
        p._dirty = False
        CacheWrapper.refs[self.address] = p
        self.obj = weakref.ref(p)
        return

    def save(self):
        if self.obj() is None:
            return
        self.obj().save()

    def __setstate__(self, d):
        log.error('setstate %s' % d)
        raise TypeError

    def __getstate__(self):
        log.error('getstate %s' % self.__dict__)
        raise TypeError

    def __hash__(self):
        return hash(self.address)

    def __cmp__(self, other):
        return cmp(self.address, other.address)

    def __str__(self):
        return 'struct_%x' % self.address
Пример #17
0
    def __init__(self, server):
        self.reasonable_sc_distance = 1500
        self.reasonable_hs_radius = 50
        edr_config = edrconfig.EDRConfig()

        try:
            with open(self.EDR_SYSTEMS_CACHE, 'rb') as handle:
                self.systems_cache = pickle.load(handle)
        except:
            self.systems_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.systems_max_age())

        try:
            with open(self.EDR_NOTAMS_CACHE, 'rb') as handle:
                self.notams_cache = pickle.load(handle)
        except:
            self.notams_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.notams_max_age())

        try:
            with open(self.EDR_SITREPS_CACHE, 'rb') as handle:
                self.sitreps_cache = pickle.load(handle)
        except:
            self.sitreps_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.sitreps_max_age())

        try:
            with open(self.EDR_CRIMES_CACHE, 'rb') as handle:
                self.crimes_cache = pickle.load(handle)
        except:
            self.crimes_cache = lrucache.LRUCache(edr_config.lru_max_size(),
                                                  edr_config.crimes_max_age())

        try:
            with open(self.EDR_TRAFFIC_CACHE, 'rb') as handle:
                self.traffic_cache = pickle.load(handle)
        except:
            self.traffic_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.traffic_max_age())

        try:
            with open(self.EDSM_SYSTEMS_CACHE, 'rb') as handle:
                self.edsm_systems_cache = pickle.load(handle)
        except:
            self.edsm_systems_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.edsm_systems_max_age())

        try:
            with open(self.EDSM_STATIONS_CACHE, 'rb') as handle:
                self.edsm_stations_cache = pickle.load(handle)
        except:
            self.edsm_stations_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.edsm_stations_max_age())

        try:
            with open(self.EDSM_FACTIONS_CACHE, 'rb') as handle:
                self.edsm_factions_cache = pickle.load(handle)
        except:
            self.edsm_factions_cache = lrucache.LRUCache(
                edr_config.lru_max_size(), edr_config.edsm_factions_max_age())

        try:
            with open(self.EDSM_SYSTEMS_WITHIN_RADIUS_CACHE, 'rb') as handle:
                self.edsm_systems_within_radius_cache = pickle.load(handle)
        except:
            self.edsm_systems_within_radius_cache = lrucache.LRUCache(
                edr_config.edsm_within_radius_max_size(),
                edr_config.edsm_systems_max_age())

        self.reports_check_interval = edr_config.reports_check_interval()
        self.notams_check_interval = edr_config.notams_check_interval()
        self.timespan = edr_config.sitreps_timespan()
        self.timespan_notams = edr_config.notams_timespan()
        self.server = server
        self.edsm_server = edsmserver.EDSMServer()
Пример #18
0
import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache, math
import config
from debug import debug_write, fn_attr

info_cache = lrucache.LRUCache(1000)
videotest = os.path.join(os.path.dirname(__file__), 'videotest.mpg')

BAD_MPEG_FPS = ['15.00']

def ffmpeg_path():
    return config.get('Server', 'ffmpeg')

# XXX BIG HACK
# subprocess is broken for me on windows so super hack
def patchSubprocess():
    o = subprocess.Popen._make_inheritable

    def _make_inheritable(self, handle):
        if not handle: return subprocess.GetCurrentProcess()
        return o(self, handle)

    subprocess.Popen._make_inheritable = _make_inheritable
mswindows = (sys.platform == "win32")
if mswindows:
    patchSubprocess()

def output_video(inFile, outFile, tsn=''):
    if tivo_compatable(inFile, tsn):
        debug_write(__name__, fn_attr(), [inFile, ' is tivo compatible'])
        f = file(inFile, 'rb')
        shutil.copyfileobj(f, outFile)
Пример #19
0
 def __init__(self):
     self.cache = lrucache.LRUCache(4096)
Пример #20
0
 def __init__(self):
     # can be reset with method `resize`
     self._cache = lrucache.LRUCache(self._DEFAULT_CACHE_SIZE)
     # never expire
     self.max_age = None
     self.enable()