- make Flags a subclass of object
- Drop the silly games with __dict__['flags'] in favor of directly
setting attributes
- Preserve the exception-on-get/set-of-unknown-attribute behavior
---
pyanaconda/flags.py | 102 ++++++++++++++++++++++++---------------------------
1 files changed, 48 insertions(+), 54 deletions(-)
# A lot of effort, but it only allows a limited set of flags to be referenced
-class Flags:
-
- def __getattr__(self, attr):
- if self.__dict__['flags'].has_key(attr):
- return self.__dict__['flags'][attr]
- raise AttributeError, attr
-
+class Flags(object):
def __setattr__(self, attr, val):
- if self.__dict__['flags'].has_key(attr):
- self.__dict__['flags'][attr] = val
- else:
+ if attr not in self.__dict__ and not self._in_init:
raise AttributeError, attr
+ else:
+ self.__dict__[attr] = val
def get(self, attr, val=None):
- if self.__dict__['flags'].has_key(attr):
- return self.__dict__['flags'][attr]
- else:
- return val
+ return getattr(self, attr, val)
+
def decideCmdlineFlag(self, flag):
- if self.__dict__['flags']['cmdline'].has_key(flag)
- and not self.__dict__['flags']['cmdline'].has_key("no" + flag)
- and self.__dict__['flags']['cmdline'][flag] != "0":
- self.__dict__['flags'][flag] = 1
+ if self.cmdline.has_key(flag)
+ and not self.cmdline.has_key("no" + flag)
+ and self.cmdline[flag] != "0":
+ setattr(self, flag, 1)
- for x in ['selinux']:
- if self.__dict__['flags']['cmdline'].has_key(x):
- if self.__dict__['flags']['cmdline'][x]:
- self.__dict__['flags'][x] = 1
- else:
- self.__dict__['flags'][x] = 0
+ if 'selinux' in self.cmdline:
+ if self.cmdline['selinux'] not in ("0", "off", "no"):
+ self.selinux = 1
+ else:
+ self.selinux = 0
self.decideCmdlineFlag('sshd')
- if self.__dict__['flags']['cmdline'].has_key("debug"):
- self.__dict__['flags']['debug'] = self.__dict__['flags']['cmdline']['debug']
+ if self.cmdline.has_key("debug"):
+ self.debug = self.cmdline['debug']
- if self.__dict__['flags']['cmdline'].has_key("rpmarch"):
- self.__dict__['flags']['targetarch'] = self.__dict__['flags']['cmdline']['rpmarch']
+ if self.cmdline.has_key("rpmarch"):
+ self.targetarch = self.cmdline['rpmarch']
if not selinux.is_selinux_enabled():
- self.__dict__['flags']['selinux'] = 0
+ self.selinux = 0
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
02-08-2012, 12:12 AM
"Brian C. Lane"
flags.py: rework/cleanup Flags object
Ack to all of these other than my style comments, which also apply to
the 4th patch.
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list