From 62268e02169f3f442ffe06a89631b2f3078e237a Mon Sep 17 00:00:00 2001 From: Alexandr Popov Date: Mon, 9 Mar 2009 13:45:24 +0300 Subject: [PATCH] adding file with OptParser object --- src/optparser.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/optparser.py diff --git a/src/optparser.py b/src/optparser.py new file mode 100644 index 0000000..beb2215 --- /dev/null +++ b/src/optparser.py @@ -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() -- 1.7.9.5