[Zope-CVS] SVN: profilestats/trunk/src/profilestats/ On add, remember file name.

Jim Fulton jim at zope.com
Mon Jan 9 19:44:16 EST 2006


Log message for revision 41245:
  On add, remember file name.
  Collect a delimiter. so perhaps we can use this for files produced on
  windows.
  

Changed:
  U   profilestats/trunk/src/profilestats/browser.py
  U   profilestats/trunk/src/profilestats/configure.zcml
  U   profilestats/trunk/src/profilestats/detail.pt
  U   profilestats/trunk/src/profilestats/stats.py
  U   profilestats/trunk/src/profilestats/table.pt
  U   profilestats/trunk/src/profilestats/tree.pt

-=-
Modified: profilestats/trunk/src/profilestats/browser.py
===================================================================
--- profilestats/trunk/src/profilestats/browser.py	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/browser.py	2006-01-10 00:44:16 UTC (rev 41245)
@@ -24,21 +24,54 @@
 
 import profilestats.stats
 
+class FileWidget(zope.app.form.browser.FileWidget):
 
+    def _toFieldValue(self, input):
+        if input is None or input == '':
+            return self.context.missing_value
+
+        try:
+            seek = input.seek
+            read = input.read
+        except AttributeError, e:
+            raise ConversionError(_('Form input is not a file object'), e)
+        else:
+            seek(0)
+            data = read()
+            if data or getattr(input, 'filename', ''):
+                return data, getattr(input, 'filename', '')
+            else:
+                return self.context.missing_value
+
+
 class Add(form.AddForm):
 
     form_fields = (
         form.Field(
-            schema.Bytes(__name__='file',
-                         title=u"profile stats file"),
-            custom_widget = zope.app.form.browser.FileWidget,
+            schema.Field(__name__='file',
+                         title=u"Profile statistics file"),
+            custom_widget = FileWidget,
             ),
+        form.Field(
+            schema.Bytes(__name__='delimiter',
+                         title=u"File path delimiter",
+                         min_length=1,
+                         max_length=1,
+                         required=False,
+                         missing_value='/',
+                         ),
+            ),
         )
 
     def create(self, data):
-        return profilestats.stats.Stats(marshal.loads(data['file']))
+        delimiter = data['delimiter']
+        data, filename = data['file']
+        return profilestats.stats.Stats(
+            marshal.loads(data),
+            filename,
+            delimiter,
+            )
         
-        
 class StatsView:
 
     detail_template = ViewPageTemplateFile('detail.pt')
@@ -47,7 +80,6 @@
 
     def __init__(self, stats, request):
         self.context = stats
-        self.stats = stats.stats
         self.request = request
 
     def tree(self):
@@ -60,16 +92,17 @@
                 self.name = name
                 self.time = time
 
+        delimiter = self.context.delimiter
         tree = Tree()
         for ((filename, lineno, func),
              (direct_calls, calls, time, cummulative, callers)
-             ) in self.stats.iteritems():
+             ) in self.context.stats.iteritems():
             if not calls:
                 continue
             
             t = tree
             t.time += time
-            for n in filename.split('/'):
+            for n in filename.split(delimiter):
                 tn = t.get(n)
                 if tn is None:
                     tn = t[n] = Tree(n)
@@ -92,7 +125,7 @@
             while len(tree) == 1:
                 k = tree.keys()[0]
                 v = tree.pop(k)
-                tree.name += '/' + k
+                tree.name += delimiter + k
                 tree.update(v)
 
             for t in tree.itervalues():
@@ -127,7 +160,7 @@
         total = 0
         for ((filename, lineno, func),
              (direct_calls, calls, time, cummulative, callers)
-             ) in self.stats.iteritems():
+             ) in self.context.stats.iteritems():
 
             if calls < 1:
                 continue
@@ -161,7 +194,7 @@
             )
 
     def detail_data(self, filename, lineno, func):
-        stats = self.stats
+        stats = self.context.stats
         key = (filename, int(lineno), func)
         direct_calls, calls, time, cummulative, callers = stats[key]
 

Modified: profilestats/trunk/src/profilestats/configure.zcml
===================================================================
--- profilestats/trunk/src/profilestats/configure.zcml	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/configure.zcml	2006-01-10 00:44:16 UTC (rev 41245)
@@ -6,9 +6,8 @@
     >
 
 <content class=".stats.Stats">
-   <implements 
-       interface="zope.app.annotation.IAttributeAnnotatable" />
-   <require permission="zope.View" attributes="stats" />
+   <implements interface="zope.app.annotation.IAttributeAnnotatable" />
+   <require permission="zope.View" attributes="stats filename delimiter" />
 </content>
 
 <browser:page

Modified: profilestats/trunk/src/profilestats/detail.pt
===================================================================
--- profilestats/trunk/src/profilestats/detail.pt	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/detail.pt	2006-01-10 00:44:16 UTC (rev 41245)
@@ -6,6 +6,7 @@
       <span tal:content="options/filename">src/foo.py</span>(<span 
           tal:content="options/lineno" >10</span>) 
       <span tal:content="options/func">foo</span>
+      in profile results <span tal:content="context/filename">mydata</span>
   </h2>
 
   <table>

Modified: profilestats/trunk/src/profilestats/stats.py
===================================================================
--- profilestats/trunk/src/profilestats/stats.py	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/stats.py	2006-01-10 00:44:16 UTC (rev 41245)
@@ -27,5 +27,7 @@
 
     interface.implements(IStats)
 
-    def __init__(self, stats):
+    def __init__(self, stats, filename='', delimiter='/'):
         self.stats = stats
+        self.filename = filename
+        self.delimiter = delimiter

Modified: profilestats/trunk/src/profilestats/table.pt
===================================================================
--- profilestats/trunk/src/profilestats/table.pt	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/table.pt	2006-01-10 00:44:16 UTC (rev 41245)
@@ -2,8 +2,8 @@
       i18n:domain="buddydemo">
 <body>
 <div metal:fill-slot="body">
-  <h2>Profile results sorted by 
-      <span tal:content="options/sortby">time</span></h2>
+  <h2>Profile results, <span tal:content="context/filename">mydata</span>, 
+      sorted by <span tal:content="options/sortby">time</span></h2>
 
   <p>Total time: <span tal:content="options/total">100.2</span></p>
 

Modified: profilestats/trunk/src/profilestats/tree.pt
===================================================================
--- profilestats/trunk/src/profilestats/tree.pt	2006-01-10 00:19:49 UTC (rev 41244)
+++ profilestats/trunk/src/profilestats/tree.pt	2006-01-10 00:44:16 UTC (rev 41245)
@@ -34,7 +34,8 @@
 </head>
 <body>
 <div metal:fill-slot="body">
-  <h2>Profile results organized by file and function</h2>
+  <h2>Profile results, <span tal:content="context/filename">mydata</span>,
+      organized by file and function</h2>
   Total time is 
   <div tal:replace="structure options/tree" />
 </div>



More information about the Zope-CVS mailing list