22"""The Planet aggregator.
33
44A flexible and easy-to-use aggregator for generating websites.
5-
6- Visit http://www.planetplanet.org/ for more information and to download
7- the latest version.
8-
9- Requires Python 2.1, recommends 2.3.
105"""
116
12- __authors__ = ["Scott James Remnant <scott@netsplit.com>" , "Jeff Waugh <jdub@perkypants.org>" ]
13- __license__ = "Python"
14-
15-
7+ import argparse
168import configparser
179import locale
1810import os
3830TEMPLATE_FILES = "examples/basic/planet.html.tmpl"
3931
4032
41- def config_get (config , section , option , default = None , raw = 0 , vars = None ):
33+ def config_get (config , section , option , default = None , raw = False , vars = None ):
4234 """Get a value from the configuration, with a default."""
4335 if config .has_option (section , option ):
4436 return config .get (section , option , raw = raw , vars = None )
@@ -51,25 +43,26 @@ def main():
5143 offline = 0
5244 verbose = 0
5345
54- for arg in sys .argv [1 :]:
55- if arg == "-h" or arg == "--help" :
56- print ("Usage: planet [options] [CONFIGFILE]" )
57- print ()
58- print ("Options:" )
59- print (" -v, --verbose DEBUG level logging during update" )
60- print (" -o, --offline Update the Planet from the cache only" )
61- print (" -h, --help Display this help message and exit" )
62- print ()
63- sys .exit (0 )
64- elif arg == "-v" or arg == "--verbose" :
65- verbose = 1
66- elif arg == "-o" or arg == "--offline" :
67- offline = 1
68- elif arg .startswith ("-" ):
69- print ("Unknown option:" , arg , file = sys .stderr )
70- sys .exit (1 )
71- else :
72- config_file = arg
46+ parser = argparse .ArgumentParser (description = "The Planet aggregator" )
47+
48+ parser .add_argument (
49+ "-v" , "--verbose" , action = "store_true" , help = "DEBUG level logging during update"
50+ )
51+ parser .add_argument (
52+ "-o" ,
53+ "--offline" ,
54+ action = "store_true" ,
55+ help = "Update the Planet from the cache only" ,
56+ )
57+ parser .add_argument (
58+ "config_file" , nargs = "?" , help = "Configuration file" , default = CONFIG_FILE
59+ )
60+
61+ args = parser .parse_args ()
62+
63+ verbose = args .verbose
64+ offline = args .offline
65+ config_file = args .config_file
7366
7467 # Read the configuration file
7568 config = configparser .ConfigParser ()
@@ -89,7 +82,9 @@ def main():
8982 else :
9083 log_level = config_get (config , "Planet" , "log_level" , LOG_LEVEL )
9184 feed_timeout = config_get (config , "Planet" , "feed_timeout" , FEED_TIMEOUT )
92- template_files = config_get (config , "Planet" , "template_files" , TEMPLATE_FILES ).split (" " )
85+ template_files = config_get (
86+ config , "Planet" , "template_files" , TEMPLATE_FILES
87+ ).split (" " )
9388
9489 # Default feed to the first feed for which there is a template
9590 if not planet_feed :
@@ -130,7 +125,9 @@ def main():
130125 try :
131126 feed_timeout = float (feed_timeout )
132127 except :
133- log .warning ("Feed timeout set to invalid value '%s', skipping" , feed_timeout )
128+ log .warning (
129+ "Feed timeout set to invalid value '%s', skipping" , feed_timeout
130+ )
134131 feed_timeout = None
135132
136133 if feed_timeout and not offline :
@@ -141,7 +138,9 @@ def main():
141138 my_planet = planet .Planet (config )
142139 my_planet .run (planet_name , planet_link , template_files , offline )
143140
144- my_planet .generate_all_files (template_files , planet_name , planet_link , planet_feed , owner_name , owner_email )
141+ my_planet .generate_all_files (
142+ template_files , planet_name , planet_link , planet_feed , owner_name , owner_email
143+ )
145144
146145
147146if __name__ == "__main__" :
0 commit comments