Skip to content

Commit 86e31f9

Browse files
committed
WIP: upgrade to 3 in truth
- starting to add typing - fixed boolean flags in many places - switch from hand-parsed args to argparse - switch from htmltmpl to jinja2 TODO: - core templates need to be converted to jinja2 - cache keys are still failing
1 parent 29e2ea5 commit 86e31f9

File tree

4 files changed

+261
-165
lines changed

4 files changed

+261
-165
lines changed

code/planet-cache.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#!/usr/bin/env python3
22
"""Planet cache tool."""
33

4-
__authors__ = ["Scott James Remnant <scott@netsplit.com>", "Jeff Waugh <jdub@perkypants.org>"]
4+
__authors__ = [
5+
"Scott James Remnant <scott@netsplit.com>",
6+
"Jeff Waugh <jdub@perkypants.org>",
7+
]
58
__license__ = "Python"
69

710

811
import configparser
9-
import shelve
1012
import os
13+
import shelve
1114
import sys
1215
import time
1316

@@ -144,7 +147,7 @@ def fit_str(string, length):
144147

145148
elif command == "list":
146149
print("Items in Channel:")
147-
for item in channel.items(hidden=1, sorted=1):
150+
for item in channel.items(hidden=True, sorted=True):
148151
print(" " + item.id)
149152
print(" " + time.strftime(planet.TIMEFMT_ISO, item.date))
150153
if hasattr(item, "title"):

code/planet.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
"""The Planet aggregator.
33
44
A 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
168
import configparser
179
import locale
1810
import os
@@ -38,7 +30,7 @@
3830
TEMPLATE_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

147146
if __name__ == "__main__":

0 commit comments

Comments
 (0)