anothergene avatar anothergene committed a080325

added autosizing for name column

Comments (0)

Files changed (1)

transmission-list.py

 
 import transmissionrpc
 
-ID_WIDTH = 5
-NAME_WIDTH = 77
-STATUS_WIDTH = 15
-PROG_WIDTH = 8
-RATIO_WIDTH = 8
-AGE_WIDTH = 15
 
 def FormatTD(self): 
     hours = self.seconds // 3600 
     return '%02d:%02d:%02d:%02d' % (self.days, hours, minutes, seconds) 
 
 def Main():
+    ID_WIDTH = 5
+    NAME_WIDTH = 50
+    STATUS_WIDTH = 15
+    PROG_WIDTH = 8
+    RATIO_WIDTH = 8
+    AGE_WIDTH = 15
+
     options = argparse.ArgumentParser(description='Removes all torrents on a given host that are either older then the given days or have a larger then given ratio')
     options.add_argument('-p', '--port', default='9091', help='port to connect on. default=9091')
     options.add_argument('-u', '--user', default='', help='The user to connect as. Defaults to empty')
     tc = transmissionrpc.Client(theargs.host, theargs.port, theargs.user, theargs.password)
     tl = tc.info()
     
-    print 'ID'.ljust(ID_WIDTH) + \
-    'Name'.ljust(NAME_WIDTH) + \
-    'Status'.ljust(STATUS_WIDTH) + \
-    'Prog'.ljust(PROG_WIDTH) + \
-    'Ratio'.ljust(RATIO_WIDTH) + \
-    'Age'.ljust(AGE_WIDTH)
-         
+    for t in tl:
+        if len(tl[t].name) > NAME_WIDTH:
+            NAME_WIDTH = len(tl[t].name) + 4
+            
+    print ('ID'.ljust(ID_WIDTH) +
+    'Name'.ljust(NAME_WIDTH) +
+    'Status'.ljust(STATUS_WIDTH) +
+    'Prog'.ljust(PROG_WIDTH) +
+    'Ratio'.ljust(RATIO_WIDTH) +
+    'Age'.ljust(AGE_WIDTH))
+                
     for t in tl:
         print str(t).ljust(ID_WIDTH) + \
         tl[t].name.ljust(NAME_WIDTH) + \
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.