adding file with OptParser object
authorAlexandr Popov <popov2al@gmail.com>
Mon, 9 Mar 2009 10:45:24 +0000 (13:45 +0300)
committerAlexandr Popov <popov2al@gmail.com>
Mon, 9 Mar 2009 10:45:24 +0000 (13:45 +0300)
src/optparser.py [new file with mode: 0644]

diff --git a/src/optparser.py b/src/optparser.py
new file mode 100644 (file)
index 0000000..beb2215
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*-coding: utf-8 -*-
+# vim: sw=4 ts=4 expandtab ai
+# pylint: disable-msg=C0301
+
+import os
+from optparse import OptionParser
+
+class OptParser(object):
+    # функция получения параметров из ком строки
+    def get(self):
+        parser = OptionParser(usage="Usage: %prog -d -c", version="%prog 0.1.0")
+        # Парсим параметры ком строки, заодно проверяя их тип
+        parser.add_option('--dir', '-d', dest='dir', type="string", \
+                help="starting path for search" )
+        parser.add_option('--count', '-c', metavar='COUNT',dest='cnt', type="int", \
+               help="count of files for print")
+        (self.options, self.args) = parser.parse_args()
+    
+        # Проверяем полученные параметры
+#        if not self.options.dir or not self.options.cnt:
+#            parser.error("options --directory or --count not present")
+        if not os.path.isdir(self.options.dir):
+            parser.error(self.options.dir, "- It`s not directory")
+        return self.options.dir, self.options.cnt
+
+    def __init__(self):
+        self.get()