Coder Social home page Coder Social logo

strizhechenko / optparse-modular-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 3 KB

I tried to find a nice way for modular optparse that would provide opportunity to create meta-utils easily.

Python 100.00%
utils python poc proof-of-concept python2 optparse modularity meta-util

optparse-modular-example's Introduction

optparse-modular-example

I tried to find a nice way for modular optparse that would provide opportunity to create meta-utils easily.

This repo is just a proof of concept.

How it works

Every top has common and specific options:

$ top1 --help
Usage: top1 [options]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  file to monitor
  -i INTERVAL, --interval=INTERVAL
                        interval between file readings in seconds
  -t TOP1_SPECIFIC1, --top1-specific1=TOP1_SPECIFIC1
                        Top1 specific option #1
  -s TOP1_SPECIFIC2, --top1-specific2=TOP1_SPECIFIC2
                        Top1 specific option #2

Here are top2 specific options:

$ top2 --help
Usage: top2 [options]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  file to monitor
  -i INTERVAL, --interval=INTERVAL
                        interval between file readings in seconds
  -u TOP2_SPECIFIC1, --top2-specific1=TOP2_SPECIFIC1
                        Top2 specific option #1
  -w TOP2_SPECIFIC2, --top2-specific2=TOP2_SPECIFIC2
                        Top2 specific option #2

And metatop has both all other tops' specific and common options:

$ metatop --help
Usage: metatop [options]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  file to monitor
  -i INTERVAL, --interval=INTERVAL
                        interval between file readings in seconds
  -t TOP1_SPECIFIC1, --top1-specific1=TOP1_SPECIFIC1
                        Top1 specific option #1
  -s TOP1_SPECIFIC2, --top1-specific2=TOP1_SPECIFIC2
                        Top1 specific option #2
  -u TOP2_SPECIFIC1, --top2-specific1=TOP2_SPECIFIC1
                        Top2 specific option #1
  -w TOP2_SPECIFIC2, --top2-specific2=TOP2_SPECIFIC2
                        Top2 specific option #2

There are still few problems:

Duplicity in utils' __main__ part:

Top1 and Top2 have simillar __main__

if __name__ == '__main__':
    top = Top1()
    top.parse_options()
    print top.options
if __name__ == '__main__':
    top = Top2()
    top.parse_options()
    print top.options

Partly it's because of difference between MetaTop and Top1/Top2:

if __name__ == '__main__':
    print MetaTop().options

BaseTop.__init__() seems to be a perfect place for parse_options() call if not this difference.

optparse-modular-example's People

Contributors

strizhechenko avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.