Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to switch the planet to python3 #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: build pages
runs-on: ubuntu-latest
container:
image: centos/python-27-centos7
image: quay.io/centos/centos:stream9
volumes:
- ${{ github.workspace }}:/opt/app-root/src

Expand Down
90 changes: 45 additions & 45 deletions planet/planet-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,48 @@
import os
import sys
import time
import dbhash
import ConfigParser
import dbm.bsd
import configparser

import planet


def usage():
print "Usage: planet-cache [options] CACHEFILE [ITEMID]..."
print
print "Examine and modify information in the Planet cache."
print
print "Channel Commands:"
print " -C, --channel Display known information on the channel"
print " -L, --list List items in the channel"
print " -K, --keys List all keys found in channel items"
print
print "Item Commands (need ITEMID):"
print " -I, --item Display known information about the item(s)"
print " -H, --hide Mark the item(s) as hidden"
print " -U, --unhide Mark the item(s) as not hidden"
print
print "Other Options:"
print " -h, --help Display this help message and exit"
print("Usage: planet-cache [options] CACHEFILE [ITEMID]...")
print()
print("Examine and modify information in the Planet cache.")
print()
print("Channel Commands:")
print(" -C, --channel Display known information on the channel")
print(" -L, --list List items in the channel")
print(" -K, --keys List all keys found in channel items")
print()
print("Item Commands (need ITEMID):")
print(" -I, --item Display known information about the item(s)")
print(" -H, --hide Mark the item(s) as hidden")
print(" -U, --unhide Mark the item(s) as not hidden")
print()
print("Other Options:")
print(" -h, --help Display this help message and exit")
sys.exit(0)

def usage_error(msg, *args):
print >>sys.stderr, msg, " ".join(args)
print >>sys.stderr, "Perhaps you need --help ?"
print(msg, " ".join(args), file=sys.stderr)
print("Perhaps you need --help ?", file=sys.stderr)
sys.exit(1)

def print_keys(item, title):
keys = item.keys()
keys = list(item.keys())
keys.sort()
key_len = max([ len(k) for k in keys ])

print title + ":"
print(title + ":")
for key in keys:
if item.key_type(key) == item.DATE:
value = time.strftime(planet.TIMEFMT_ISO, item[key])
else:
value = str(item[key])
print " %-*s %s" % (key_len, key, fit_str(value, 74 - key_len))
print(" %-*s %s" % (key_len, key, fit_str(value, 74 - key_len)))

def fit_str(string, length):
if len(string) <= length:
Expand Down Expand Up @@ -116,24 +116,24 @@ def fit_str(string, length):

# Open the cache file directly to get the URL it represents
try:
db = dbhash.open(cache_file)
db = dbm.bsd.open(cache_file)
url = db["url"]
db.close()
except dbhash.bsddb._db.DBError, e:
print >>sys.stderr, cache_file + ":", e.args[1]
except dbm.bsd.bsddb._db.DBError as e:
print(cache_file + ":", e.args[1], file=sys.stderr)
sys.exit(1)
except KeyError:
print >>sys.stderr, cache_file + ": Probably not a cache file"
print(cache_file + ": Probably not a cache file", file=sys.stderr)
sys.exit(1)

# Now do it the right way :-)
my_planet = planet.Planet(ConfigParser.ConfigParser())
my_planet = planet.Planet(configparser.ConfigParser())
my_planet.cache_directory = os.path.dirname(cache_file)
channel = planet.Channel(my_planet, url)

for item_id in ids:
if not channel.has_item(item_id):
print >>sys.stderr, item_id + ": Not in channel"
print(item_id + ": Not in channel", file=sys.stderr)
sys.exit(1)

# Do the user's bidding
Expand All @@ -146,49 +146,49 @@ def fit_str(string, length):
print_keys(item, "Item Keys for %s" % item_id)

elif command == "list":
print "Items in Channel:"
print("Items in Channel:")
for item in channel.items(hidden=1, sorted=1):
print " " + item.id
print " " + time.strftime(planet.TIMEFMT_ISO, item.date)
print(" " + item.id)
print(" " + time.strftime(planet.TIMEFMT_ISO, item.date))
if hasattr(item, "title"):
print " " + fit_str(item.title, 70)
print(" " + fit_str(item.title, 70))
if hasattr(item, "hidden"):
print " (hidden)"
print(" (hidden)")

elif command == "keys":
keys = {}
for item in channel.items():
for key in item.keys():
for item in list(channel.items()):
for key in list(item.keys()):
keys[key] = 1

keys = keys.keys()
keys = list(keys.keys())
keys.sort()

print "Keys used in Channel:"
print("Keys used in Channel:")
for key in keys:
print " " + key
print
print(" " + key)
print()

print "Use --item to output values of particular items."
print("Use --item to output values of particular items.")

elif command == "hide":
for item_id in ids:
item = channel.get_item(item_id)
if hasattr(item, "hidden"):
print item_id + ": Already hidden."
print(item_id + ": Already hidden.")
else:
item.hidden = "yes"

channel.cache_write()
print "Done."
print("Done.")

elif command == "unhide":
for item_id in ids:
item = channel.get_item(item_id)
if hasattr(item, "hidden"):
del(item.hidden)
else:
print item_id + ": Not hidden."
print(item_id + ": Not hidden.")

channel.cache_write()
print "Done."
print("Done.")
26 changes: 13 additions & 13 deletions planet/planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import sys
import time
import locale
import urlparse
import urllib.parse

import planet

from ConfigParser import ConfigParser
from configparser import ConfigParser

# Default configuration file path
CONFIG_FILE = "config.ini"
Expand Down Expand Up @@ -55,20 +55,20 @@ def main():

for arg in sys.argv[1:]:
if arg == "-h" or arg == "--help":
print "Usage: planet [options] [CONFIGFILE]"
print
print "Options:"
print " -v, --verbose DEBUG level logging during update"
print " -o, --offline Update the Planet from the cache only"
print " -h, --help Display this help message and exit"
print
print("Usage: planet [options] [CONFIGFILE]")
print()
print("Options:")
print(" -v, --verbose DEBUG level logging during update")
print(" -o, --offline Update the Planet from the cache only")
print(" -h, --help Display this help message and exit")
print()
sys.exit(0)
elif arg == "-v" or arg == "--verbose":
verbose = 1
elif arg == "-o" or arg == "--offline":
offline = 1
elif arg.startswith("-"):
print >>sys.stderr, "Unknown option:", arg
print("Unknown option:", arg, file=sys.stderr)
sys.exit(1)
else:
config_file = arg
Expand All @@ -77,7 +77,7 @@ def main():
config = ConfigParser()
config.read(config_file)
if not config.has_section("Planet"):
print >>sys.stderr, "Configuration missing [Planet] section."
print("Configuration missing [Planet] section.", file=sys.stderr)
sys.exit(1)

# Read the [Planet] config section
Expand All @@ -99,7 +99,7 @@ def main():
for template_file in template_files:
name = os.path.splitext(os.path.basename(template_file))[0]
if name.find('atom')>=0 or name.find('rss')>=0:
planet_feed = urlparse.urljoin(planet_link, name)
planet_feed = urllib.parse.urljoin(planet_link, name)
break

# Define locale
Expand All @@ -117,7 +117,7 @@ def main():
locale_ok = True
break
if not locale_ok:
print >>sys.stderr, "Unsupported locale setting."
print("Unsupported locale setting.", file=sys.stderr)
sys.exit(1)

# Activate logging
Expand Down
Loading