Blame SOURCES/0002-When-tabcreatedb.py-is-called-without-any-options-pr.patch

b385cc
From 87cb7fb1ee81da34e0a6b40efba561236dff772a Mon Sep 17 00:00:00 2001
b385cc
From: Mike FABIAN <mfabian@redhat.com>
b385cc
Date: Thu, 23 Jan 2014 23:26:57 +0100
b385cc
Subject: [PATCH 2/2] When tabcreatedb.py is called without any options, print
b385cc
 a usage message
b385cc
b385cc
Do not just show a cryptic backtrace.
b385cc
b385cc
Resolves: rhbz#1049760
b385cc
See: https://bugzilla.redhat.com/show_bug.cgi?id=1049760
b385cc
---
b385cc
 engine/ibus-table-createdb.sgml |  8 ++++----
b385cc
 engine/tabcreatedb.py           | 43 +++++++++++++++++++++++++----------------
b385cc
 2 files changed, 30 insertions(+), 21 deletions(-)
b385cc
b385cc
diff --git a/engine/ibus-table-createdb.sgml b/engine/ibus-table-createdb.sgml
b385cc
index 6a1e439..e14ffb2 100644
b385cc
--- a/engine/ibus-table-createdb.sgml
b385cc
+++ b/engine/ibus-table-createdb.sgml
b385cc
@@ -108,7 +108,7 @@ manpage.1: manpage.sgml
b385cc
 	  <option><replaceable>database-file</replaceable></option>
b385cc
         </term>
b385cc
         <listitem>
b385cc
-          <para><replaceable>database-file</replaceable> specifies the file which will contain the binary database for the IME.  The default is ''.</para>
b385cc
+          <para><replaceable>database-file</replaceable> specifies the file name for the binary database for the IME. The default is ''. If the file name of the database is not specified, the file name of the source file before the first '.' will be appended with '.db' and that will be used as the file name of the database.</para>
b385cc
         </listitem>
b385cc
       </varlistentry>
b385cc
         <term><option>-s</option>
b385cc
@@ -125,7 +125,7 @@ manpage.1: manpage.sgml
b385cc
 	  <option><replaceable>extra-words-file</replaceable></option>
b385cc
         </term>
b385cc
         <listitem>
b385cc
-          <para><replaceable>extra-words-file</replaceable> specifies the file for the extra words for the IME.  The default is ''.</para>
b385cc
+          <para><replaceable>extra-words-file</replaceable> specifies the file name for the extra words for the IME.  The default is ''.</para>
b385cc
         </listitem>
b385cc
       </varlistentry>
b385cc
       <varlistentry>
b385cc
@@ -134,7 +134,7 @@ manpage.1: manpage.sgml
b385cc
 	  <option><replaceable>pinyin-file</replaceable></option>
b385cc
         </term>
b385cc
         <listitem>
b385cc
-          <para><replaceable>pinyin-file</replaceable> specifies the source file for the pinyin.  The default is /usr/share/ibus-table/data/pinyin_table.txt.bz2.</para>
b385cc
+          <para><replaceable>pinyin-file</replaceable> specifies the source file for the pinyin.  The default is '/usr/share/ibus-table/data/pinyin_table.txt.bz2'.</para>
b385cc
         </listitem>
b385cc
       </varlistentry>
b385cc
       <varlistentry>
b385cc
@@ -150,7 +150,7 @@ manpage.1: manpage.sgml
b385cc
           <option>--create-index-only</option>
b385cc
         </term>
b385cc
         <listitem>
b385cc
-          <para>Only create an index for an existing database.</para>
b385cc
+          <para>Only create an index for an existing database. Specifying the file name of the binary database with the -n or --name option is required when this option is used.</para>
b385cc
         </listitem>
b385cc
       </varlistentry>
b385cc
       <varlistentry>
b385cc
diff --git a/engine/tabcreatedb.py b/engine/tabcreatedb.py
b385cc
index 6694b13..fb6d7e2 100644
b385cc
--- a/engine/tabcreatedb.py
b385cc
+++ b/engine/tabcreatedb.py
b385cc
@@ -62,46 +62,55 @@ class InvalidTableName(Exception):
b385cc
         return 'Value of NAME attribute (%s) cannot contain any of %r and must be all ascii' % (self.table_name, _invalid_keyname_chars)
b385cc
 
b385cc
 # we use OptionParser to parse the cmd arguments :)
b385cc
-opt_parser = OptionParser()
b385cc
+usage = "usage: %prog [options]"
b385cc
+opt_parser = OptionParser(usage=usage)
b385cc
 
b385cc
 opt_parser.add_option( '-n', '--name',
b385cc
-        action = 'store', dest='name',default = None,
b385cc
-        help = 'set the database name we will use, default is %default')
b385cc
+        action = 'store', dest='name',default = '',
b385cc
+        help = "specifies the file name for the binary database for the IME. The default is '%default'. If the file name of the database is not specified, the file name of the source file before the first '.' will be appended with '.db' and that will be used as the file name of the database.")
b385cc
 
b385cc
 opt_parser.add_option( '-s', '--source',
b385cc
-        action = 'store', dest='source', default = 'xingma.txt.bz2',
b385cc
-        help = 'specifies the file which contains the source file of the IME.  The default is %default')
b385cc
+        action = 'store', dest='source', default = '',
b385cc
+        help = "specifies the file which contains the source of the IME.  The default is '%default'.")
b385cc
 
b385cc
 opt_parser.add_option( '-e', '--extra',
b385cc
         action = 'store', dest='extra', default = '',
b385cc
-        help = 'specifies the file for the extra words for the IME.  The default is %default')
b385cc
+        help = "specifies the file name for the extra words for the IME.  The default is '%default'.")
b385cc
 
b385cc
 opt_parser.add_option( '-p', '--pinyin',
b385cc
         action = 'store', dest='pinyin', default = '/usr/share/ibus-table/data/pinyin_table.txt.bz2',
b385cc
-        help = 'specifies the source file  for the  pinyin.  The default is %default')
b385cc
+        help = "specifies the source file for the  pinyin.  The default is '%default'.")
b385cc
 
b385cc
 opt_parser.add_option( '-o', '--no-create-index',
b385cc
         action = 'store_false', dest='index', default = True,
b385cc
-        help = 'do not create an index for a database (Only for distrubution purposes, a normal user should not use this flag!)')
b385cc
+        help = 'Do not create an index for a database (Only for distrubution purposes, a normal user should not use this flag!)')
b385cc
 
b385cc
 opt_parser.add_option( '-i', '--create-index-only',
b385cc
         action = 'store_true', dest='only_index', default = False,
b385cc
-        help = 'only create an index for an existing database')
b385cc
+        help = 'Only create an index for an existing database. Specifying the file name of the binary database with the -n or --name option is required when this option is used.')
b385cc
 
b385cc
 opt_parser.add_option( '-d', '--debug',
b385cc
         action = 'store_true', dest='debug', default = False,
b385cc
-        help = 'print extra debug messages')
b385cc
-
b385cc
-
b385cc
+        help = 'Print extra debug messages.')
b385cc
 
b385cc
 opts,args = opt_parser.parse_args()
b385cc
-if not opts.name and opts.only_index:
b385cc
-    print 'Please give me the database you want to create index on'
b385cc
-    sys.exit(2)
b385cc
-
b385cc
-if not opts.name:
b385cc
+if opts.only_index:
b385cc
+    if not opts.name:
b385cc
+        opt_parser.print_help()
b385cc
+        print('\nPlease specify the file name of the database you want to create an index on!')
b385cc
+        sys.exit(2)
b385cc
+    if not os.path.exists(opts.name) or not os.path.isfile(opts.name):
b385cc
+        opt_parser.print_help()
b385cc
+        print("\nThe database file '%s' does not exist." %opts.name)
b385cc
+        sys.exit(2)
b385cc
+
b385cc
+if not opts.name and opts.source:
b385cc
     opts.name = os.path.basename(opts.source).split('.')[0] + '.db'
b385cc
 
b385cc
+if not opts.name:
b385cc
+    opt_parser.print_help()
b385cc
+    print '\nYou need to specify the file which contains the source of the IME!'
b385cc
+    sys.exit(2)
b385cc
 
b385cc
 def main ():
b385cc
     def debug_print ( message ):
b385cc
-- 
b385cc
1.8.4.2
b385cc