r137 - /debtorrent/trunk/debtorrent.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Mon Jul 9 04:33:20 UTC 2007


Author: camrdale-guest
Date: Mon Jul  9 04:33:20 2007
New Revision: 137

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=137
Log:
Add new dameon script, modified from btlaunchmany.

Added:
    debtorrent/trunk/debtorrent.py
      - copied, changed from r136, debtorrent/trunk/btlaunchmany.py

Copied: debtorrent/trunk/debtorrent.py (from r136, debtorrent/trunk/btlaunchmany.py)
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/debtorrent.py?rev=137&op=diff
==============================================================================
--- debtorrent/trunk/btlaunchmany.py (original)
+++ debtorrent/trunk/debtorrent.py Mon Jul  9 04:33:20 2007
@@ -1,14 +1,12 @@
 #!/usr/bin/env python
 #
-# Written by John Hoffman
-# Modified by Cameron Dale
 # see LICENSE.txt for license information
 #
 # $Id$
 
-"""A multiple downloader for debtorrent.
+"""A multiple downloader daemon for debtorrent.
 
-This script implements a command-line client for managing multiple 
+This script implements a daemon for managing multiple 
 debtorrent downloads.
 
 """
@@ -30,15 +28,6 @@
 import sys, os
 from DebTorrent import version, report_email
 from DebTorrent.ConfigDir import ConfigDir
-
-assert sys.version >= '2', "Install Python 2.0 or greater"
-try:
-    True
-except:
-    True = 1
-    False = 0
-
-PROFILER = False
 
 def hours(n):
     """Formats seconds into a human-readable time.
@@ -147,22 +136,22 @@
     ] )
     try:
         try:
-            configdir = ConfigDir('launchmany', params[params.index('--config_dir')+1])
+            configdir = ConfigDir('debtorrent', params[params.index('--config_dir')+1])
         except:
-            configdir = ConfigDir('launchmany')
+            configdir = ConfigDir('debtorrent')
         defaultsToIgnore = ['responsefile', 'url', 'priority']
         configdir.setDefaults(defaults,defaultsToIgnore)
         configdefaults = configdir.loadConfig()
         defaults.append(('save_options',0,
          "whether to save the current options as the new default configuration " +
-         "(only for btlaunchmany.py)"))
+         "(only for debtorrent.py)"))
         config, args = parseargs(params, defaults, 0, 0, configdefaults)
         if config['save_options']:
             configdir.saveConfig(config)
         configdir.deleteOldCacheData(config['expire_cache_data'])
     except ValueError, e:
         print 'error: ' + str(e) + '\n'
-        print "Usage: btlaunchmany.py <global options>\n"
+        print "Usage: debtorrent.py <global options>\n"
         print get_usage(defaults, 80, configdefaults)
         exit(1)
 
@@ -173,16 +162,27 @@
         print 'please report this to '+report_email
 
 if __name__ == '__main__':
-    if argv[1:] == ['--version']:
-        print version
-        exit(0)
-
-    if PROFILER:
-        import profile, pstats
-        p = profile.Profile()
-        p.runcall(run, argv[1:])
-        p.dump_stats('btlaunchmany.pstat')
-#        pstats.Stats(p).strip_dirs().sort_stats('cumulative').print_stats()
-        pstats.Stats(p).strip_dirs().sort_stats('time').print_stats()
+    if len(argv) > 1:
+        if argv[1] == ['--version']:
+            print version
+            exit(0)
+        elif argv[1] == ['--profile']:
+            import profile, pstats
+            p = profile.Profile()
+            p.runcall(run, argv[2:])
+            p.dump_stats('debtorrent.pstat')
+            # pstats.Stats(p).strip_dirs().sort_stats('cumulative').print_stats()
+            pstats.Stats(p).strip_dirs().sort_stats('time').print_stats()
+        elif argv[1] == ['--foreground']:
+            run(argv[2:])
+        else:
+            pid = os.fork()
+            if pid != 0:
+                exit(0)
+            run(argv[1:])
     else:
+        pid = os.fork()
+        if pid != 0:
+            exit(0)
         run(argv[1:])
+        




More information about the Debtorrent-commits mailing list