"pid", "returncode", "files")
_file_names = ("fetcher", "out")
- _files_dict = slot_dict_class(_file_names)
+ _files_dict = slot_dict_class(_file_names, prefix="")
_bufsize = 4096
def start(self):
files = self.files
if log_file is not None:
- files["out"] = open(log_file, "a")
+ files.out = open(log_file, "a")
portage.util.apply_secpass_permissions(log_file,
uid=portage.portage_uid, gid=portage.portage_gid,
mode=0660)
if fd == sys.stderr.fileno():
sys.stderr.flush()
- files["out"] = os.fdopen(os.dup(fd_pipes[1]), 'w')
+ files.out = os.fdopen(os.dup(fd_pipes[1]), 'w')
master_fd, slave_fd = os.pipe()
self.pid = retval[0]
os.close(slave_fd)
- files["fetcher"] = os.fdopen(master_fd, 'r')
- self.register(files["fetcher"].fileno(),
+ files.fetcher = os.fdopen(master_fd, 'r')
+ self.register(files.fetcher.fileno(),
select.POLLIN, self._output_handler)
def _output_handler(self, fd, event):
files = self.files
buf = array.array('B')
try:
- buf.fromfile(files["fetcher"], self._bufsize)
+ buf.fromfile(files.fetcher, self._bufsize)
except EOFError:
pass
if buf:
- buf.tofile(files["out"])
- files["out"].flush()
+ buf.tofile(files.out)
+ files.out.flush()
else:
- self.unregister(files["fetcher"].fileno())
+ self.unregister(files.fetcher.fileno())
for f in files.values():
f.close()
"pid", "returncode", "files")
_file_names = ("log", "stdout", "ebuild")
- _files_dict = slot_dict_class(_file_names)
+ _files_dict = slot_dict_class(_file_names, prefix="")
_bufsize = 4096
def start(self):
if logfile:
os.close(slave_fd)
- files["log"] = open(logfile, 'a')
- files["stdout"] = os.fdopen(os.dup(fd_pipes_orig[1]), 'w')
- files["ebuild"] = os.fdopen(master_fd, 'r')
- self.register(files["ebuild"].fileno(),
+ files.log = open(logfile, 'a')
+ files.stdout = os.fdopen(os.dup(fd_pipes_orig[1]), 'w')
+ files.ebuild = os.fdopen(master_fd, 'r')
+ self.register(files.ebuild.fileno(),
select.POLLIN, self._output_handler)
def _output_handler(self, fd, event):
files = self.files
buf = array.array('B')
try:
- buf.fromfile(files["ebuild"], self._bufsize)
+ buf.fromfile(files.ebuild, self._bufsize)
except EOFError:
pass
if buf:
- buf.tofile(files["stdout"])
- files["stdout"].flush()
- buf.tofile(files["log"])
- files["log"].flush()
+ buf.tofile(files.stdout)
+ files.stdout.flush()
+ buf.tofile(files.log)
+ files.log.flush()
else:
- self.unregister(files["ebuild"].fileno())
+ self.unregister(files.ebuild.fileno())
for f in files.values():
f.close()
"locked", "files", "pid", "pkg_path", "returncode", "_lock_obj")
_file_names = ("fetcher", "out")
- _files_dict = slot_dict_class(_file_names)
+ _files_dict = slot_dict_class(_file_names, prefix="")
_bufsize = 4096
def __init__(self, **kwargs):
files = self.files
if log_file is not None:
- files["out"] = open(log_file, "a")
+ files.out = open(log_file, "a")
portage.util.apply_secpass_permissions(log_file,
uid=portage.portage_uid, gid=portage.portage_gid,
mode=0660)
if fd == sys.stderr.fileno():
sys.stderr.flush()
- files["out"] = os.fdopen(os.dup(fd_pipes[1]), 'w')
+ files.out = os.fdopen(os.dup(fd_pipes[1]), 'w')
master_fd, slave_fd = os.pipe()
fcntl.fcntl(master_fd, fcntl.F_SETFL,
self.pid = retval[0]
os.close(slave_fd)
- files["fetcher"] = os.fdopen(master_fd, 'r')
- self.register(files["fetcher"].fileno(),
+ files.fetcher = os.fdopen(master_fd, 'r')
+ self.register(files.fetcher.fileno(),
select.POLLIN, self._output_handler)
def _output_handler(self, fd, event):
files = self.files
buf = array.array('B')
try:
- buf.fromfile(files["fetcher"], self._bufsize)
+ buf.fromfile(files.fetcher, self._bufsize)
except EOFError:
pass
if buf:
- buf.tofile(files["out"])
- files["out"].flush()
+ buf.tofile(files.out)
+ files.out.flush()
else:
- self.unregister(files["fetcher"].fileno())
+ self.unregister(files.fetcher.fileno())
for f in files.values():
f.close()
if self.locked:
_slot_dict_classes = weakref.WeakValueDictionary()
-def slot_dict_class(keys):
+def slot_dict_class(keys, prefix="_val_"):
"""
Generates mapping classes that behave similar to a dict but store values
as object attributes that are allocated via __slots__. Instances of these
objects have a smaller memory footprint than a normal dict object.
@param keys: Fixed set of allowed keys
- @type keys: iterable
+ @type keys: Iterable
+ @param prefix: a prefix to use when mapping
+ attribute names from keys
+ @type prefix: String
@rtype: SlotDict
@returns: A class that constructs SlotDict instances
having the specified keys.
keys_set = keys
else:
keys_set = frozenset(keys)
- v = _slot_dict_classes.get(keys_set)
+ v = _slot_dict_classes.get((keys_set, prefix))
if v is None:
class SlotDict(object):
allowed_keys = keys_set
+ _prefix = prefix
__slots__ = ("__weakref__",) + \
- tuple("_val_" + k for k in allowed_keys)
+ tuple(prefix + k for k in allowed_keys)
def __iter__(self):
for k, v in self.iteritems():
def iteritems(self):
for k in self.allowed_keys:
try:
- yield (k, getattr(self, "_val_" + k))
+ yield (k, getattr(self, self._prefix + k))
except AttributeError:
pass
def __delitem__(self, k):
try:
- delattr(self, "_val_" + k)
+ delattr(self, self._prefix + k)
except AttributeError:
raise KeyError(k)
def __setitem__(self, k, v):
- setattr(self, "_val_" + k, v)
+ setattr(self, self._prefix + k, v)
def setdefault(self, key, default=None):
try:
def __getitem__(self, k):
try:
- return getattr(self, "_val_" + k)
+ return getattr(self, self._prefix + k)
except AttributeError:
raise KeyError(k)
return default
def __contains__(self, k):
- return hasattr(self, "_val_" + k)
+ return hasattr(self, self._prefix + k)
def has_key(self, k):
return k in self
def clear(self):
for k in self.allowed_keys:
try:
- delattr(self, "_val_" + k)
+ delattr(self, self._prefix + k)
except AttributeError:
pass