[Erp5-report] r34717 nicolas - /erp5/trunk/utils/erp5mechanize/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 22 11:28:44 CEST 2010


Author: nicolas
Date: Thu Apr 22 11:28:43 2010
New Revision: 34717

URL: http://svn.erp5.org?rev=34717&view=rev
Log:
Factorise shared code to improve consistency


Added:
    erp5/trunk/utils/erp5mechanize/erp5_mechanize_common.py
Modified:
    erp5/trunk/utils/erp5mechanize/multi_userperzope.py
    erp5/trunk/utils/erp5mechanize/timeperstep.py
    erp5/trunk/utils/erp5mechanize/timerepartitionperstep.py
    erp5/trunk/utils/erp5mechanize/userperzope.py

Added: erp5/trunk/utils/erp5mechanize/erp5_mechanize_common.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/erp5_mechanize_common.py?rev=34717&view=auto
==============================================================================
--- erp5/trunk/utils/erp5mechanize/erp5_mechanize_common.py (added)
+++ erp5/trunk/utils/erp5mechanize/erp5_mechanize_common.py [utf8] Thu Apr 22 11:28:43 2010
@@ -1,0 +1,21 @@
+# -*- coding: utf-8 -*-
+import sys
+CSV_SEPARATOR = ';'
+
+def parse_csv_line(line, sep):
+  line = line.replace('\n', '')
+  item_list = line.split(sep)
+  for pos in xrange(len(item_list)):
+    item = item_list[pos].strip("'")
+    item_list[pos] = item
+  return item_list
+
+def output_csv(fields=[], separator=CSV_SEPARATOR):
+  sys.stdout.write(separator.join([repr(v) for v in fields]))
+  sys.stdout.write('\n')
+
+def result_cmp(a, b):
+  dif = cmp(a['user'], b['user'])
+  if dif != 0:
+    return dif
+  return cmp(a['duration'], b['duration'])

Modified: erp5/trunk/utils/erp5mechanize/multi_userperzope.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/multi_userperzope.py?rev=34717&r1=34716&r2=34717&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/multi_userperzope.py [utf8] (original)
+++ erp5/trunk/utils/erp5mechanize/multi_userperzope.py [utf8] Thu Apr 22 11:28:43 2010
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 # Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
@@ -28,6 +29,8 @@
 ##############################################################################
 import sys
 import getopt
+from erp5_mechanize_common import CSV_SEPARATOR, parse_csv_line, output_csv,\
+        result_cmp
 
 """
   Same as userperzope.py, except that multiple files are just concatenated
@@ -43,28 +46,6 @@
     return -maximum_failure / user_count
   else:
     return maximum_failure
-
-def result_cmp(a, b):
-  dif = cmp(a['user'], b['user'])
-  if dif != 0:
-    return dif
-  return cmp(a['duration'], b['duration'])
-
-def parse_csv_line(line, sep):
-  line = line.replace('\n','')
-  item_list = line.split(sep)
-  for pos in xrange(len(item_list)):
-    item = item_list[pos]
-    if item[0] == "'":
-      item = item[1:]
-    if item[-1] == "'":
-      item = item[:-1]
-    item_list[pos] = item
-  return item_list
-
-def output_csv(fields=[], separator=','):
-  sys.stdout.write(separator.join([repr(v) for v in fields]))
-  sys.stdout.write('\n')
 
 try:
   opt_list, arg_list = getopt.getopt(sys.argv[1:], '', ['maximum_duration=', 'maximum_failure=', 'csv_separator=', 'default_step_number=', 'ignore_first_run'])
@@ -100,7 +81,7 @@
 ''' % (sys.argv[0], )
   sys.exit(2)
 
-csv_separator = ','
+csv_separator = CSV_SEPARATOR
 maximum_duration = None
 maximum_failure = None
 ignore_first_run = False

Modified: erp5/trunk/utils/erp5mechanize/timeperstep.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/timeperstep.py?rev=34717&r1=34716&r2=34717&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/timeperstep.py [utf8] (original)
+++ erp5/trunk/utils/erp5mechanize/timeperstep.py [utf8] Thu Apr 22 11:28:43 2010
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 # Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
@@ -28,22 +29,7 @@
 ##############################################################################
 import sys
 import getopt
-
-def parse_csv_line(line, sep):
-  line = line.replace('\n','')
-  item_list = line.split(sep)
-  for pos in xrange(len(item_list)):
-    item = item_list[pos]
-    if item[0] == "'":
-      item = item[1:]
-    if item[-1] == "'":
-      item = item[:-1]
-    item_list[pos] = item
-  return item_list
-
-def output_csv(fields=[], separator=','):
-  sys.stdout.write(separator.join([repr(v) for v in fields]))
-  sys.stdout.write('\n')
+from erp5_mechanize_common import CSV_SEPARATOR, parse_csv_line, output_csv
 
 try:
   opt_list, arg_list = getopt.getopt(sys.argv[1:], '', ['csv_separator=', 'ignore_first_run'])
@@ -55,7 +41,7 @@
 ''' % (sys.argv[0], )
   sys.exit(2)
 
-csv_separator = ';'
+csv_separator = CSV_SEPARATOR
 ignore_first_run = False
 for o, a in opt_list:
   if o == '--csv_separator':

Modified: erp5/trunk/utils/erp5mechanize/timerepartitionperstep.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/timerepartitionperstep.py?rev=34717&r1=34716&r2=34717&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/timerepartitionperstep.py [utf8] (original)
+++ erp5/trunk/utils/erp5mechanize/timerepartitionperstep.py [utf8] Thu Apr 22 11:28:43 2010
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 # Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
@@ -28,22 +29,7 @@
 ##############################################################################
 import sys
 import getopt
-
-def parse_csv_line(line, sep):
-  line = line.replace('\n','')
-  item_list = line.split(sep)
-  for pos in xrange(len(item_list)):
-    item = item_list[pos]
-    if item[0] == "'":
-      item = item[1:]
-    if item[-1] == "'":
-      item = item[:-1]
-    item_list[pos] = item
-  return item_list
-
-def output_csv(fields=[], separator=','):
-  sys.stdout.write(separator.join([repr(v) for v in fields]))
-  sys.stdout.write('\n')
+from erp5_mechanize_common import CSV_SEPARATOR, parse_csv_line, output_csv
 
 try:
   opt_list, arg_list = getopt.getopt(sys.argv[1:], '', ['csv_separator=', 'ignore_first_run'])
@@ -55,7 +41,7 @@
 ''' % (sys.argv[0], )
   sys.exit(2)
 
-csv_separator = ','
+csv_separator = CSV_SEPARATOR
 ignore_first_run = False
 for o, a in opt_list:
   if o == '--csv_separator':

Modified: erp5/trunk/utils/erp5mechanize/userperzope.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5mechanize/userperzope.py?rev=34717&r1=34716&r2=34717&view=diff
==============================================================================
--- erp5/trunk/utils/erp5mechanize/userperzope.py [utf8] (original)
+++ erp5/trunk/utils/erp5mechanize/userperzope.py [utf8] Thu Apr 22 11:28:43 2010
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 # Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
@@ -28,6 +29,8 @@
 ##############################################################################
 import sys
 import getopt
+from erp5_mechanize_common import CSV_SEPARATOR, parse_csv_line, output_csv,\
+         result_cmp
 
 def compute_max_error_count(user_count, maximum_failure):
   if maximum_failure is None:
@@ -37,28 +40,6 @@
     return -maximum_failure / user_count
   else:
     return maximum_failure
-
-def result_cmp(a, b):
-  dif = cmp(a['user'], b['user'])
-  if dif != 0:
-    return dif
-  return cmp(a['duration'], b['duration'])
-
-def parse_csv_line(line, sep):
-  line = line.replace('\n','')
-  item_list = line.split(sep)
-  for pos in xrange(len(item_list)):
-    item = item_list[pos]
-    if item[0] == "'":
-      item = item[1:]
-    if item[-1] == "'":
-      item = item[:-1]
-    item_list[pos] = item
-  return item_list
-
-def output_csv(fields=[], separator=','):
-  sys.stdout.write(separator.join([repr(v) for v in fields]))
-  sys.stdout.write('\n')
 
 try:
   opt_list, arg_list = getopt.getopt(sys.argv[1:], '', ['maximum_duration=', 'maximum_failure=', 'csv_separator=', 'default_step_number=', 'ignore_first_run'])
@@ -94,7 +75,7 @@
 ''' % (sys.argv[0], )
   sys.exit(2)
 
-csv_separator = ','
+csv_separator = CSV_SEPARATOR
 maximum_duration = None
 maximum_failure = None
 ignore_first_run = False




More information about the Erp5-report mailing list