Last active
October 13, 2017 13:19
-
-
Save deeplook/4812aff91b6e87fee79ee59308f41153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
An example file actually using an auto-upgrading tool. | |
WARNING: | |
If you find this script inside a GitHub gist, be warned that | |
its gist ID might change without notice! In this case please | |
look for similar filenames until this might become part of | |
a proper package... | |
""" | |
import os | |
import sys | |
import argparse | |
from autoupgrade import GistUpgrader | |
__version__ = "0.0.2" | |
def fib(n): | |
""" | |
Return n-th Fibonacci number. | |
This is a simple and slow, recursive implementation. | |
""" | |
if n <= 1: | |
return n | |
else: | |
return fib(n - 2) + fib(n - 1) | |
def main(): | |
parser = argparse.ArgumentParser( | |
description="Return n-th Fibonacci number.", | |
epilog="Copyleft 2017, Dinu Gherman", | |
formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument("--version", | |
action="store_true", | |
help="Show version and quit.") | |
parser.add_argument("--verbose", | |
action="store_true", | |
help="Be more verbose.") | |
parser.add_argument("--upgrade-check", | |
action="store_true", | |
help="Check for available upgrade") | |
parser.add_argument("--upgrade", | |
action="store_true", | |
help="Perform upgrade to latest version") | |
opts = parser.parse_args() | |
if opts.version: | |
print(__version__) | |
sys.exit(0) | |
gist_id = "4812aff91b6e87fee79ee59308f41153" | |
upgrader = GistUpgrader(gist_id, verbose=opts.verbose) | |
if opts.upgrade_check: | |
# show available updates | |
filename = os.path.basename(__file__) | |
upgrader.upgrade_check(filename, __version__, verbose=True) | |
sys.exit(0) | |
elif opts.upgrade: | |
# upgrade to latest available update | |
upgrader.upgrade_script(__file__, verbose=opts.verbose) | |
sys.exit(0) | |
else: | |
print("v. " + __version__) | |
print(list(map(fib, range(10)))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment