[PATCH] warning for big attached or included files option.

Carl Chenet carl.chenet at ohmytux.com
Mon Apr 20 22:18:44 UTC 2009


---
 bin/reportbug |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/bin/reportbug b/bin/reportbug
index dcae600..1738a6f 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -95,6 +95,15 @@ def stopmsg(filename):
         'it as bug report body, please take a look at the "-i FILE, '
         '--include=FILE" option.\n', filename)
 
+def check_attachment_size(attachfile):
+    """Check the attachment size"""
+    statinfo = os.stat(attachfile)
+    attachsize = statinfo[6]
+    if attachsize >= 10485760:
+        ewrite('Your attachment size is greater than 10MBytes. You could '
+                'experience limitations from your internet service provider '
+                'while sending your bugreport with this attachment.\n')
+
 def include_file_in_report(message, message_filename,
                            attachment_filenames, package_name,
                            include_filename, charset, inline=False):
@@ -223,6 +232,8 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
                 if attachfile:
                     attachfile = os.path.expanduser(attachfile)
                     if os.access(attachfile, os.R_OK) and os.path.isfile(attachfile):
+                        if not options.attachsize:
+                            check_attachment_size(attachfile)
                         invalid = False
                         inline = (x == 'i')
                         (message, filename, attachments) = include_file_in_report(
@@ -725,6 +736,8 @@ def main():
                       help='include the specified file in the report')
     parser.add_option('-A', '--attach', action='append', dest='attachments',
                       help='attach the specified file to the report')
+    parser.add_option('--no-attachment-size', action='store_true', dest='attachsize',
+                      default=False, help='do not warn the user when attachment size is too big')
     parser.add_option('-b', '--no-query-bts', action='store_true',
                       dest='dontquery',help='do not query the BTS for reports')
     parser.add_option('--query-bts', action='store_false', dest='dontquery',
@@ -831,6 +844,10 @@ def main():
             if not os.path.exists(os.path.expanduser(attachment)):
                 print 'The attachment file %s does not exist.' % attachment
                 any_missing = True
+            else:
+                if not options.attachsize:
+                    check_attachment_size(os.path.expanduser(attachment))
+
         if any_missing:
             print "The above files are missing, so can't be attached; exiting"
             sys.exit(1)
-- 
1.5.4.3


--=-Om1IOJ1NETrKCtGSLX6h--






More information about the Reportbug-maint mailing list