Aggiunta gestione degli errori nello spostamento

Leonardo [2010-06-15 08:46]
Aggiunta gestione degli errori nello spostamento
Filename
example_script.py
mlmanager.py
diff --git a/example_script.py b/example_script.py
index 64b1d62..6ed72e1 100755
--- a/example_script.py
+++ b/example_script.py
@@ -27,6 +27,11 @@ mlmanager.mail_server = "localhost"
 # Users that should be notified on error, default is "owner"
 mlmanager.error_recipients = [ "owner", "admin@example.org" ]

+# Incoming directory for your mldonkey downloads. Directory are not handled now
+# This is the default so it really doesn't matter that you set it if it is
+# /var/lib/mldonkey/incoming/files
+mlmanager.files_incoming = "/var/lib/mldonkey/incoming/files"
+
 # Our mldonkey supports auto commit so we don't need username and password, but we
 # could also use download = mlmanager.Download(username = "user", password = "password")
 download = mlmanager.Download()
diff --git a/mlmanager.py b/mlmanager.py
index bfd8684..6ea69d0 100644
--- a/mlmanager.py
+++ b/mlmanager.py
@@ -255,6 +255,10 @@ class Download():
     if not destination_folder.endswith(os.path.sep):
       destination_folder += os.path.sep

+    if not os.path.exists(destination_folder):
+      self._notify_error("Destination directory %s does not exists" % destination_folder)
+      return
+
     shutil.move (self._dest_path, destination_folder + filename)

     # Update _dest_path
@@ -270,6 +274,7 @@ class Download():

     if not self._committed:
       self.commit()
+
     shutil.copy(self._dest_path, destination)

ViewGit