Python style guide for Cumin
by Trevor McKay
Hi folks,
Let's follow the traditional style guide for Python,
http://www.python.org/dev/peps/pep-0008/.
I think we've been close to this historically, if there are places
where the code is off we can fix
it over time. Or, if there is a consistent deviation throughout the
code we can document it and
retain the deviation.
I'll be playing with pylint soon, I think it has an option for
enforcing PEP 8. We'll see what it says.
Best,
Trevor
12 years, 3 months
Mail filters, for what it's worth
by Trevor McKay
Hi all,
You've likely already done this, but since we're moving toward using
the developer list for technical discussions rather than just commit
messages...
I created a mail filter for filing commits into one folder (this is
applied first) and messages to cumin-developers(a)lists.fedorahosted.org
into another folder.
The filter for commits looks like "from contains @fedoraproject.org"
since commits always come through the FAS accounts and "subject matches
r* - *" since commit messages always start with r# followed by a dash.
That ought to be sufficient.
Thought this might be helpful.
Best,
Trev
12 years, 3 months
r5189 - trunk/cumin/python/cumin/inventory
by croberts@fedoraproject.org
Author: croberts
Date: 2012-01-18 20:21:39 +0000 (Wed, 18 Jan 2012)
New Revision: 5189
Modified:
trunk/cumin/python/cumin/inventory/system.py
Log:
Addressing BZ 782902 by ensuring that we are fetching all of the sesame data before merging it with the wallaby data. Prevviously, we were only getting the first 25 sesame records that came back...not always in the same order. This would cause the sesame data to "flicker" in the interface.
Modified: trunk/cumin/python/cumin/inventory/system.py
===================================================================
--- trunk/cumin/python/cumin/inventory/system.py 2012-01-18 19:20:57 UTC (rev 5188)
+++ trunk/cumin/python/cumin/inventory/system.py 2012-01-18 20:21:39 UTC (rev 5189)
@@ -296,30 +296,33 @@
return len(self.get_data(values, options))
def get_data(self, values, options):
- #first, fetch all the sql data, unsorted since we will sort it after merging the wallaby data
+ #first, fetch all the sql data, unsorted since we will sort and limit it after merging the wallaby data
requested_sort_field = options.sort_field
+ requested_limit = options.limit
+ requested_offset = options.offset
options.sort_field = None
+ options.limit = 10000
+ options.offset = 0
sqldata = super(WallabyAndSqlAdapter, self).get_data(values, options)
#now get the wallaby data
wallaby_nodes = self.app.wallaby.get_data(WBTypes.NODES)
data = list()
-
if len(sqldata) > 0 and len(wallaby_nodes) > 0: #means that we have both sesame and wallaby data
#now merge them
for i, node in enumerate(wallaby_nodes):
- match_index = [i for i, y in enumerate(sqldata) if y[1] == node.name]
- if len(match_index) > 0:
- ## merge-in the wallaby data to the matched node entry in sqldata
- new_record = list(sqldata[match_index[0]])
- new_record.append(", ".join(self.app.wallaby.get_tag_names(node)))
- new_record.append(node.last_checkin)
- sqldata[match_index[0]] = tuple(new_record)
- else:
- # there was no match found, add a wallaby-only row
- data_row = tuple([node.name, node.name, "", "", "", "", ", ".join(self.app.wallaby.get_tag_names(node)), node.last_checkin])
- sqldata.append(data_row)
+ match_index = [i for i, y in enumerate(sqldata) if y[1] == node.name]
+ if len(match_index) > 0:
+ ## merge-in the wallaby data to the matched node entry in sqldata
+ new_record = list(sqldata[match_index[0]])
+ new_record.append(", ".join(self.app.wallaby.get_tag_names(node)))
+ new_record.append(node.last_checkin)
+ sqldata[match_index[0]] = tuple(new_record)
+ else:
+ # there was no match found, add a wallaby-only row
+ data_row = tuple([node.name, node.name, "", "", "", "", ", ".join(self.app.wallaby.get_tag_names(node)), node.last_checkin])
+ sqldata.append(data_row)
data = sqldata
elif len(sqldata) > 0: # we only have sesame data
for node in sqldata:
@@ -333,10 +336,12 @@
data_row = tuple([node.name, node.name, "", "", "", "", ", ".join(self.app.wallaby.get_tag_names(node)), node.last_checkin])
data.append(data_row)
- options.sort_field = requested_sort_field
+ options.sort_field = requested_sort_field
+ options.limit = requested_limit
+ options.offset = requested_offset
data = self.sort_rows(data, options)
data = self.limit_rows(data, options)
-
+
return data
def limit_rows(self, rows, options):
12 years, 3 months
r5188 - branches/stability/cumin/python/cumin/inventory
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-01-18 19:20:57 +0000 (Wed, 18 Jan 2012)
New Revision: 5188
Modified:
branches/stability/cumin/python/cumin/inventory/system.py
Log:
Merge revision 5187 from trunk.
BZ782485
Modified: branches/stability/cumin/python/cumin/inventory/system.py
===================================================================
--- branches/stability/cumin/python/cumin/inventory/system.py 2012-01-18 14:14:00 UTC (rev 5187)
+++ branches/stability/cumin/python/cumin/inventory/system.py 2012-01-18 19:20:57 UTC (rev 5188)
@@ -406,7 +406,12 @@
return field
def render_cell_title(self, session, record):
- return record[self.field.index]
+ value = ""
+ try:
+ value = record[self.field.index]
+ except Exception:
+ pass #no data to show is a reasonable case if a node has wallaby, but doesn't really use it
+ return value
def render_text_align(self, session):
return "right"
Property changes on: branches/stability/cumin/python/cumin/inventory/system.py
___________________________________________________________________
Deleted: svn:mergeinfo
-
12 years, 3 months
r5187 - trunk/cumin/python/cumin/inventory
by croberts@fedoraproject.org
Author: croberts
Date: 2012-01-18 14:14:00 +0000 (Wed, 18 Jan 2012)
New Revision: 5187
Modified:
trunk/cumin/python/cumin/inventory/system.py
Log:
Addressing BZ 782485 by handling a potential exception where wallaby data was possible but not actually present.
Modified: trunk/cumin/python/cumin/inventory/system.py
===================================================================
--- trunk/cumin/python/cumin/inventory/system.py 2012-01-12 22:36:13 UTC (rev 5186)
+++ trunk/cumin/python/cumin/inventory/system.py 2012-01-18 14:14:00 UTC (rev 5187)
@@ -406,7 +406,12 @@
return field
def render_cell_title(self, session, record):
- return record[self.field.index]
+ value = ""
+ try:
+ value = record[self.field.index]
+ except Exception:
+ pass #no data to show is a reasonable case if a node has wallaby, but doesn't really use it
+ return value
def render_text_align(self, session):
return "right"
12 years, 3 months
r5186 - trunk/cumin/bin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-01-12 22:36:13 +0000 (Thu, 12 Jan 2012)
New Revision: 5186
Modified:
trunk/cumin/bin/cumin-database
Log:
Use the /usr/bin/postgresql-setup script to initialize the database if it exists
rather than 'service postgresql initdb' or 'service postgresql start'.
This supports installlation on Fedora 16+.
Modified: trunk/cumin/bin/cumin-database
===================================================================
--- trunk/cumin/bin/cumin-database 2012-01-12 22:29:20 UTC (rev 5185)
+++ trunk/cumin/bin/cumin-database 2012-01-12 22:36:13 UTC (rev 5186)
@@ -233,11 +233,16 @@
# will leave the service running, which is different than initdb,
# but that is fine at this point because it is restarted after
# the call to configure anyway.
- echo -e "\nAttempting to use initdb option..."
- run "/sbin/service postgresql initdb" || {
- echo -e "\ninitdb option not supported, using start..."
- run "/sbin/service postgresql start"
- }
+ if [[ -f "/usr/bin/postgresql-setup" ]]; then
+ echo -e "using postgresql-setup..."
+ run "/usr/bin/postgresql-setup initdb"
+ else
+ echo -e "\nAttempting to use initdb option..."
+ run "/sbin/service postgresql initdb" || {
+ echo -e "\ninitdb option not supported, using start..."
+ run "/sbin/service postgresql start"
+ }
+ fi
# now check again, to make sure one of the two methods worked
check-initialized &> /dev/null || {
12 years, 3 months
r5185 - trunk/cumin/python/cumin/inventory
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-01-12 22:29:20 +0000 (Thu, 12 Jan 2012)
New Revision: 5185
Modified:
trunk/cumin/python/cumin/inventory/system.py
Log:
Merge revision 5184 from branch stability, BZ771642
Modified: trunk/cumin/python/cumin/inventory/system.py
===================================================================
--- trunk/cumin/python/cumin/inventory/system.py 2012-01-09 20:13:23 UTC (rev 5184)
+++ trunk/cumin/python/cumin/inventory/system.py 2012-01-12 22:29:20 UTC (rev 5185)
@@ -172,22 +172,50 @@
def __init__(self, app, name, system):
super(SystemTagSet, self).__init__(app, name)
self.system = system
+ self.main_tmpl = WidgetTemplate(self, "html")
def render_title(self, session):
return "Tags"
-
- def render_tags(self, session):
+
+ def _get_name(self, session):
+ node_name = ""
system = self.system.get(session)
try:
node_name = system.nodeName
except:
node_name = self.frame.id.get(session)
- tags = self.app.wallaby.get_tag_names(node_name)
-
+ return node_name
+
+ def render_tags(self, session):
+ node_name = self._get_name(session)
+ try:
+ tags = self.app.wallaby.get_tag_names(node_name)
+ except AttributeError:
+ tags = []
tags_string = ", ".join(tags)
return tags_string
+ def do_render(self, session, *args):
+ if self.defer_enabled and not getattr(session, "background", None):
+ writer = Writer()
+ self.__defer_tmpl.render(writer, session, *args)
+ return writer.to_string()
+ else:
+ writer = Writer()
+ # if we have an object, we're in good shape
+ # otherwise, show the "no content" template
+ node_name = self._get_name(session)
+ if self.frame.object.get(session) or \
+ type(node_name) in (str,unicode) and node_name != "":
+ self.main_tmpl.render(writer, session, *args)
+ else:
+ self.nocontent_tmpl.render(writer, session, *args)
+ return writer.to_string()
+
+ def render_error_msg(self, session, *args):
+ return "Host data may have changed. Return to the Inventory page and try again"
+
class SystemTags(Widget):
def __init__(self, app, name, system):
super(SystemTags, self).__init__(app, name)
12 years, 3 months
Thought on where to store user role information in relation to LDAP
by Trevor McKay
Hi,
I was thinking about user roles and where to store them. I think it
would be nice to have the option of putting role information in LDAP for
customers that are using LDAP.
So, that would mean optionally adding a field to whatever flavor of
user record is being used for LDAP, with a well known name.
Thoughts on how to do this:
1) Decide on a name for role information, such as "cuminRoles", or allow
the name of the field to be set in a configuration file.
2) When authorizing external users, look in the LDAP record for
"cuminRoles"
3) If role information cannot be found, look in the cumin database (as
it does now)
4) If no role information has been found in either place, default to
"user" role
What do you think? Good idea? Customers that want role data in LDAP
would have to add the field to existing records (not sure how to do
that, but I am guessing it would not be too hard with a script).
Note, the "script" mechanism could also be extended to allow retrieval
of roles.
Users can always choose to store role information in the cumin
database, as they do now.
Best,
Trevor
12 years, 3 months
r5184 - in branches/stability: cumin/python/cumin/inventory sage/python/sage/wallaby
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-01-09 20:13:23 +0000 (Mon, 09 Jan 2012)
New Revision: 5184
Modified:
branches/stability/cumin/python/cumin/inventory/system.py
branches/stability/sage/python/sage/wallaby/wallabyoperations.py
Log:
Return [] from get_tag_names() in wallabyoperations.py if the node object does not
contain a name attribute. This is a catchall to prevent exceptions.
Modify system.py so that an error message is displayed by the Configuration tab in cases
where Sesame data has changed after drilldown from the Inventory tab.
BZ771642
Modified: branches/stability/cumin/python/cumin/inventory/system.py
===================================================================
--- branches/stability/cumin/python/cumin/inventory/system.py 2012-01-04 17:13:48 UTC (rev 5183)
+++ branches/stability/cumin/python/cumin/inventory/system.py 2012-01-09 20:13:23 UTC (rev 5184)
@@ -172,22 +172,50 @@
def __init__(self, app, name, system):
super(SystemTagSet, self).__init__(app, name)
self.system = system
+ self.main_tmpl = WidgetTemplate(self, "html")
def render_title(self, session):
return "Tags"
-
- def render_tags(self, session):
+
+ def _get_name(self, session):
+ node_name = ""
system = self.system.get(session)
try:
node_name = system.nodeName
except:
node_name = self.frame.id.get(session)
- tags = self.app.wallaby.get_tag_names(node_name)
-
+ return node_name
+
+ def render_tags(self, session):
+ node_name = self._get_name(session)
+ try:
+ tags = self.app.wallaby.get_tag_names(node_name)
+ except AttributeError:
+ tags = []
tags_string = ", ".join(tags)
return tags_string
+ def do_render(self, session, *args):
+ if self.defer_enabled and not getattr(session, "background", None):
+ writer = Writer()
+ self.__defer_tmpl.render(writer, session, *args)
+ return writer.to_string()
+ else:
+ writer = Writer()
+ # if we have an object, we're in good shape
+ # otherwise, show the "no content" template
+ node_name = self._get_name(session)
+ if self.frame.object.get(session) or \
+ type(node_name) in (str,unicode) and node_name != "":
+ self.main_tmpl.render(writer, session, *args)
+ else:
+ self.nocontent_tmpl.render(writer, session, *args)
+ return writer.to_string()
+
+ def render_error_msg(self, session, *args):
+ return "Host data may have changed. Return to the Inventory page and try again"
+
class SystemTags(Widget):
def __init__(self, app, name, system):
super(SystemTags, self).__init__(app, name)
Modified: branches/stability/sage/python/sage/wallaby/wallabyoperations.py
===================================================================
--- branches/stability/sage/python/sage/wallaby/wallabyoperations.py 2012-01-04 17:13:48 UTC (rev 5183)
+++ branches/stability/sage/python/sage/wallaby/wallabyoperations.py 2012-01-09 20:13:23 UTC (rev 5184)
@@ -414,16 +414,20 @@
on the specified node.
'''
names = []
+ n = None
if type(node) in (str, unicode):
n = node
+ elif hasattr(node, "name"):
+ n = node.name
+ if n is None:
+ log.debug("WallabyOperations: get_tag_names(), parameter 'node' yields no name, returning []")
else:
- n = node.name
- self._lock.acquire()
- try:
- if n in self._cache[WBTypes.NODES].data:
- names = self._cache[WBTypes.NODES].data[n].getTags()
- finally:
- self._lock.release()
+ self._lock.acquire()
+ try:
+ if n in self._cache[WBTypes.NODES].data:
+ names = self._cache[WBTypes.NODES].data[n].getTags()
+ finally:
+ self._lock.release()
return names
def create_tags(self, names):
12 years, 3 months
r5183 - trunk/sage/python/sage/wallaby
by tmckay@fedoraproject.org
Author: tmckay
Date: 2012-01-04 17:13:48 +0000 (Wed, 04 Jan 2012)
New Revision: 5183
Modified:
trunk/sage/python/sage/wallaby/wallabyoperations.py
Log:
Check for "name" attribute on node argument when node is not a string in get_tag_names. Return empty list if name cannot be determined.
BZ771642
Modified: trunk/sage/python/sage/wallaby/wallabyoperations.py
===================================================================
--- trunk/sage/python/sage/wallaby/wallabyoperations.py 2011-12-22 18:32:48 UTC (rev 5182)
+++ trunk/sage/python/sage/wallaby/wallabyoperations.py 2012-01-04 17:13:48 UTC (rev 5183)
@@ -414,16 +414,20 @@
on the specified node.
'''
names = []
+ n = None
if type(node) in (str, unicode):
n = node
+ elif hasattr(node, "name"):
+ n = node.name
+ if n is None:
+ log.debug("WallabyOperations: get_tag_names(), parameter 'node' yields no name, returning []")
else:
- n = node.name
- self._lock.acquire()
- try:
- if n in self._cache[WBTypes.NODES].data:
- names = self._cache[WBTypes.NODES].data[n].getTags()
- finally:
- self._lock.release()
+ self._lock.acquire()
+ try:
+ if n in self._cache[WBTypes.NODES].data:
+ names = self._cache[WBTypes.NODES].data[n].getTags()
+ finally:
+ self._lock.release()
return names
def create_tags(self, names):
12 years, 4 months