-#!/usr/bin/env python2
-
-VERSION = "2.1"
-
+#!/usr/bin/env python3
import asyncore
import asynchat
import socket
import os
+import pickle
import random
import sys
import time
from optparse import OptionParser
import logging
-try:
- logging.basicConfig(format="%(levelname)s: %(message)s")
-except TypeError:
-# Python 2.3's logging.basicConfig does not support parameters
- logging.basicConfig()
-
-try:
- import cPickle as pickle
-except ImportError:
- import pickle
+logging.basicConfig(format="%(levelname)s: %(message)s")
try:
# Required libraries
import asyncsched
import wallchanger
-except ImportError, e:
+except ImportError as e:
logging.critical("Missing libraries! Exiting...", exc_info=1)
sys.exit(1)
fd = open(filename, 'wb')
pickle.dump(self, fd, 2)
logging.debug("Cache successfully stored")
- except Exception, e:
+ except Exception as e:
warning("Storing cache: %s" % e)
def load_cache(self, filename):
tmp.paths.sort()
if self.paths != tmp.paths:
- raise ValueError, "Path list changed"
+ raise ValueError("Path list changed")
# Overwrite this object with the other
for attr, value in tmp.__dict__.items():
return True
- except Exception, e:
+ except Exception as e:
logging.warning("Loading cache: %s" % e)
return False
fd = open(filename, 'wb')
pickle.dump(self, fd, 2)
logging.debug("Cache successfully stored")
- except Exception, e:
+ except Exception as e:
logging.warning("Storing cache", exc_info=1)
def get_current_image(self):
logging.debug('Added path "%s" to the list' % path)
for dirpath, dirs, filenames in os.walk(path):
logging.debug('Scanning "%s" for images' % dirpath)
- if self.directories.has_key(dirpath):
+ if dirpath in self.directories:
continue
filenames = list(filter_images(filenames))
if len(filenames):
asynchat.async_chat.__init__(self, sock)
self.cycler = cycler
self.ibuffer = []
- self.set_terminator("\n")
+ self.set_terminator(b'\n')
def collect_incoming_data(self, data):
- self.ibuffer.append(data)
+ self.ibuffer.append(data.decode("ascii"))
def found_terminator(self):
line = "".join(self.ibuffer).lower()
try:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(options.socket_filename)
- print >>sys.stderr, "Server is already running! Sending exit command."
- sock = sock.makefile()
+ print("Server is already running! Sending exit command.", file=sys.stderr)
+ sock = sock.makefile("w")
sock.write("cmd exit\n")
sock.close()
- except Exception, e:
+ except Exception as e:
pass
try:
try:
asyncsched.loop()
except KeyboardInterrupt:
- print
+ print()
cycler.finish()
def do_client(options, args):
args = ["next"]
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(options.socket_filename)
- sock = sock.makefile()
+ sock = sock.makefile(mode="w")
for i, cmd in enumerate(args):
sock.write("cmd %s\n" % cmd)
if i < len(args) - 1:
cycler.init(options, paths, oneshot=True)
def build_parser():
- parser = OptionParser(version="%prog " + VERSION,
+ parser = OptionParser(
description = "Cycles through random background images.",
usage =
"\n(server) %prog [options] dir [dir2 ...]"
try:
do_client(options, args)
return
- except Exception, e:
- print >>sys.stderr, "Failed to connect to server:", e
+ except Exception as e:
+ print("Failed to connect to server:", e, file=sys.stderr)
if __name__ == "__main__":
-#!/usr/bin/env python2
+#!/usr/bin/env python3
# Copyright 2008 Greg Darke <greg@tsukasa.net.au>
# Copyright 2008 James Bunton <jamesbunton@fastmail.fm>
# Licensed for distribution under the GPL version 2, check COPYING for details
# This is a cross platform/cross window manager way to change your wallpaper
-import commands, sys, os, os.path, time
+import subprocess, sys, os, os.path, time
import logging
try:
import PIL, PIL.Image
logging.warning("Failed to set background: wallchanger.set_image(%s), changer=%s", filename, changer)
def check_cmd(cmd):
- return commands.getstatusoutput(cmd)[0] == 0
+ return subprocess.getstatusoutput(cmd)[0] == 0
def init(*args, **kwargs):
"""Desktop Changer factory"""
return False
cmd = """osascript -e 'tell application "finder" to set desktop picture to posix file "%s"'""" % filename
logging.debug(cmd)
- return not commands.getstatusoutput(cmd)[0]
+ return not subprocess.getstatusoutput(cmd)[0]
class WIN32Changer(BaseChanger):
name = "Windows"
try:
filename = sys.argv[1]
except:
- print >>sys.stderr, "Usage: %s filename" % sys.argv[0]
+ print("Usage: %s filename" % sys.argv[0], file=sys.stderr)
sys.exit(1)
main(filename)