comparison roundup/admin.py @ 1544:6db2cbcd390e

finally, tables autosize columns [SF#609070]
author Richard Jones <richard@users.sourceforge.net>
date Sun, 23 Mar 2003 06:07:05 +0000
parents 800b5896e14a
children ab2aa490d713
comparison
equal deleted inserted replaced
1543:5a6fb50800b9 1544:6db2cbcd390e
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 # 18 #
19 # $Id: admin.py,v 1.45 2003-03-21 04:02:12 richard Exp $ 19 # $Id: admin.py,v 1.46 2003-03-23 06:07:05 richard Exp $
20 20
21 '''Administration commands for maintaining Roundup trackers. 21 '''Administration commands for maintaining Roundup trackers.
22 ''' 22 '''
23 23
24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil
93 props = {} 93 props = {}
94 for arg in args: 94 for arg in args:
95 if arg.find('=') == -1: 95 if arg.find('=') == -1:
96 raise UsageError, _('argument "%(arg)s" not propname=value' 96 raise UsageError, _('argument "%(arg)s" not propname=value'
97 )%locals() 97 )%locals()
98 try: 98 l = arg.split('=')
99 key, value = arg.split('=') 99 if len(l) < 2:
100 except ValueError:
101 raise UsageError, _('argument "%(arg)s" not propname=value' 100 raise UsageError, _('argument "%(arg)s" not propname=value'
102 )%locals() 101 )%locals()
102 key, value = l[0], '='.join(l[1:])
103 if value: 103 if value:
104 props[key] = value 104 props[key] = value
105 else: 105 else:
106 props[key] = None 106 props[key] = None
107 return props 107 return props
749 '''Usage: table classname [property[,property]*] 749 '''Usage: table classname [property[,property]*]
750 List the instances of a class in tabular form. 750 List the instances of a class in tabular form.
751 751
752 Lists all instances of the given class. If the properties are not 752 Lists all instances of the given class. If the properties are not
753 specified, all properties are displayed. By default, the column widths 753 specified, all properties are displayed. By default, the column widths
754 are the width of the property names. The width may be explicitly defined 754 are the width of the largest value. The width may be explicitly defined
755 by defining the property as "name:width". For example:: 755 by defining the property as "name:width". For example::
756 roundup> table priority id,name:10 756 roundup> table priority id,name:10
757 Id Name 757 Id Name
758 1 fatal-bug 758 1 fatal-bug
759 2 bug 759 2 bug
760 3 usability 760 3 usability
761 4 feature 761 4 feature
762
763 Also to make the width of the column the width of the label,
764 leave a trailing : without a width on the property. E.G.
765 roundup> table priority id,name:
766 Id Name
767 1 fata
768 2 bug
769 3 usab
770 4 feat
771
772 will result in a the 4 character wide "Name" column.
762 ''' 773 '''
763 if len(args) < 1: 774 if len(args) < 1:
764 raise UsageError, _('Not enough arguments supplied') 775 raise UsageError, _('Not enough arguments supplied')
765 classname = args[0] 776 classname = args[0]
766 777
788 # now figure column widths 799 # now figure column widths
789 props = [] 800 props = []
790 for spec in prop_names: 801 for spec in prop_names:
791 if ':' in spec: 802 if ':' in spec:
792 name, width = spec.split(':') 803 name, width = spec.split(':')
793 props.append((name, int(width))) 804 if width == '':
805 props.append((name, len(spec)))
806 else:
807 props.append((name, int(width)))
794 else: 808 else:
795 props.append((spec, len(spec))) 809 # this is going to be slow
796 810 maxlen = len(spec)
811 for nodeid in cl.list():
812 curlen = len(str(cl.get(nodeid, spec)))
813 if curlen > maxlen:
814 maxlen = curlen
815 props.append((spec, maxlen))
816
797 # now display the heading 817 # now display the heading
798 print ' '.join([name.capitalize().ljust(width) for name,width in props]) 818 print ' '.join([name.capitalize().ljust(width) for name,width in props])
799 819
800 # and the table data 820 # and the table data
801 for nodeid in cl.list(): 821 for nodeid in cl.list():

Roundup Issue Tracker: http://roundup-tracker.org/