summaryrefslogtreecommitdiffstats
path: root/utils/log_picker/sending/ftpsender.py
diff options
context:
space:
mode:
authorTomas Mlcoch <tmlcoch@redhat.com>2010-09-22 13:33:21 +0200
committerTomas Mlcoch <tmlcoch@redhat.com>2010-10-11 09:41:23 +0200
commitdf2b090bff38c8e7535aaf53a5ac4559f9d2b199 (patch)
tree996885af9f99b27d413fee3361ba32f91cf9c50a /utils/log_picker/sending/ftpsender.py
parent44291bb687a7f1575e447da2879b5b5d6c6ce3ed (diff)
downloadanaconda-df2b090bff38c8e7535aaf53a5ac4559f9d2b199.tar.gz
anaconda-df2b090bff38c8e7535aaf53a5ac4559f9d2b199.tar.xz
anaconda-df2b090bff38c8e7535aaf53a5ac4559f9d2b199.zip
Add logpicker tool into utils
The Logpicker is a simple utility for log reporting. It obtains a dump from the Anaconda + some another information and creates a compressed archive. Then it's able to send the archive to: - Bugzilla (in case of Fedora) - Red Hat Ticketing System (in case of RHEL) - email - FTP server - another computer via SCP - local filesystem The dump from the Anaconda is obtained by the signal SIGUSR2. Other information gathered by the Logpicker are: - Filesystem structure image (list of directories and files in ram disk). - Output from commands "dmsetup ls --tree" and "dmsetup info -c". The Logpicker is easy to extend. So you can easily add your own log gathering classes. The main advantage of this utility is that all important logs can be easily sended (reported) by only one command without break an instalation. Example of use: logpicker --bugzilla --login=bzlogin --idbug=999999
Diffstat (limited to 'utils/log_picker/sending/ftpsender.py')
-rw-r--r--utils/log_picker/sending/ftpsender.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/utils/log_picker/sending/ftpsender.py b/utils/log_picker/sending/ftpsender.py
new file mode 100644
index 000000000..92f7184cb
--- /dev/null
+++ b/utils/log_picker/sending/ftpsender.py
@@ -0,0 +1,47 @@
+import os
+import urlparse
+import ftplib
+from log_picker.sending.senderbaseclass import SenderBaseClass
+from log_picker.sending.senderbaseclass import SenderError
+
+# This class uses code from module report.plugins.scp
+
+class FtpSender(SenderBaseClass):
+
+ def __init__(self, *args, **kwargs):
+ SenderBaseClass.__init__(self, args, kwargs)
+ self.host = None
+ self.username = None
+ self.password = None
+
+ def set_host(self, host):
+ if not host.startswith('ftp://'):
+ host = 'ftp://' + host
+ self.host = host
+
+ def set_login(self, username, password):
+ self.username = username
+ self.password = password
+
+ def sendfile(self, filename, contenttype):
+ _, netloc, path, _, _, _ = urlparse.urlparse(self.host)
+ if netloc.find(':') > 0:
+ netloc, port = netloc.split(':')
+ else:
+ port = 21
+
+ try:
+ ftp = ftplib.FTP()
+ ftp.connect(netloc, port)
+ if self.username:
+ ftp.login(self.username, self.password)
+ else:
+ ftp.login()
+ ftp.cwd(path)
+ ftp.set_pasv(True)
+ ftp.storbinary('STOR %s' % os.path.basename(filename), \
+ file(filename))
+ ftp.quit()
+ except ftplib.all_errors, e:
+ raise SenderError("FTP upload failed: %(error)s" % {'error':e})
+