Use the print function everywhere

python modernize.py --no-six -f libmodernize.fixes.fix_print -w

With manual fixes as the import was put always on top.
This commit is contained in:
Laurent Bachelier 2014-10-06 14:23:20 +02:00
commit 74a4ef6723
73 changed files with 499 additions and 442 deletions

View file

@ -18,6 +18,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from datetime import datetime, timedelta
import logging
@ -138,7 +139,7 @@ class BoobotBrowser(StandardBrowser):
# meta charset=...
encoding = meta.attrib.get('charset', encoding).lower()
except Exception as e:
print e
print(e)
finally:
r.seek(0)
if encoding == 'iso-8859-1' or not encoding:
@ -159,7 +160,7 @@ class BoobotBrowser(StandardBrowser):
title = ' '.join(title.splitlines())
except AssertionError as e:
# invalid HTML
print e
print(e)
return content_type, hsize, title
@ -377,7 +378,7 @@ class Boobot(SingleServerIRCBot):
for msg in getattr(self, func)(backend, _id):
yield msg
except Exception as e:
print get_backtrace()
print(get_backtrace())
yield u'Oops: [%s] %s' % (type(e).__name__, e)
break
@ -394,7 +395,7 @@ class Boobot(SingleServerIRCBot):
except BrowserUnavailable as e:
yield u'URL (error): %s' % e
except Exception as e:
print get_backtrace()
print(get_backtrace())
yield u'Oops: [%s] %s' % (type(e).__name__, e)
def obj_info_video(self, backend, id):
@ -418,7 +419,7 @@ def main():
try:
bot.start()
except KeyboardInterrupt:
print "Stopped."
print("Stopped.")
thread.stop()

View file

@ -18,6 +18,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import subprocess
import os
import re
@ -69,10 +71,10 @@ class Downloadboob(object):
for local_link_name in dirList:
link_name = self.links_directory + "/" + local_link_name
if not self.check_link(link_name):
print u"Remove %s" % link_name
print(u"Remove %s" % link_name)
os.remove(link_name)
else:
print u"Keep %s" % link_name
print(u"Keep %s" % link_name)
def check_link(self, link_name):
if os.path.islink(link_name):
@ -85,10 +87,10 @@ class Downloadboob(object):
return True
def download(self, pattern=None, sortby=CapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None, title_exclude=[], id_regexp=None):
print "For backend %s, search for '%s'" % (backend_name, pattern)
print("For backend %s, search for '%s'" % (backend_name, pattern))
# create directory for links
print " create link to %s" % self.links_directory
print(" create link to %s" % self.links_directory)
if not os.path.isdir(self.links_directory):
os.makedirs(self.links_directory)
@ -101,17 +103,17 @@ class Downloadboob(object):
if not self.is_downloaded(video):
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
if not(self.is_excluded(video.title, title_exclude)) and self.id_regexp_matched(video.id, id_regexp):
print " %s\n Id:%s\n Duration:%s" % (video.title, video.id, video.duration)
print(" %s\n Id:%s\n Duration:%s" % (video.title, video.id, video.duration))
videos.append(video)
else:
print "Already downloaded, check %s" % video.id
print("Already downloaded, check %s" % video.id)
self.backend.fill_video(video, ('url','title', 'url', 'duration'))
linkname = self.get_linkname(video)
if not os.path.exists(linkname):
self.remove_download(video)
# download videos
print "Downloading..."
print("Downloading...")
for video in videos:
self.do_download(video)
@ -164,7 +166,7 @@ class Downloadboob(object):
# already empty
return
print 'Remove video %s' % video.title
print('Remove video %s' % video.title)
# Empty it to keep information we have already downloaded it.
with open(path, 'w'):
@ -175,23 +177,23 @@ class Downloadboob(object):
idname = self.get_filename(video, relative=True)
absolute_idname = self.get_filename(video, relative=False)
if not os.path.islink(linkname) and os.path.isfile(absolute_idname):
print "%s -> %s" % (linkname, idname)
print("%s -> %s" % (linkname, idname))
os.symlink(idname, linkname)
def do_download(self, video):
if not video:
print >>sys.stderr, 'Video not found: %s' % video
print('Video not found: %s' % video, file=sys.stderr)
return 3
if not video.url:
print >>sys.stderr, 'Error: the direct URL is not available.'
print('Error: the direct URL is not available.', file=sys.stderr)
return 4
def check_exec(executable):
with open('/dev/null', 'w') as devnull:
process = subprocess.Popen(['which', executable], stdout=devnull)
if process.wait() != 0:
print >>sys.stderr, 'Please install "%s"' % executable
print('Please install "%s"' % executable, file=sys.stderr)
return False
return True
@ -220,14 +222,14 @@ config.read(['/etc/downloadboob.conf', os.path.expanduser('~/downloadboob.conf')
try:
links_directory=os.path.expanduser(config.get('main','directory', '.'))
except ConfigParser.NoSectionError:
print "Please create a documentation file (see the README file and the downloadboob.conf example file)"
print("Please create a documentation file (see the README file and the downloadboob.conf example file)")
sys.exit(2)
links_directory=links_directory.decode('utf-8')
download_directory=os.path.join(links_directory, DOWNLOAD_DIRECTORY)
print "Downloading to %s" % (links_directory)
print("Downloading to %s" % (links_directory))
for section in config.sections():
if section != "main":

View file

@ -18,6 +18,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
try:
import sqlite3 as sqlite
except ImportError as e:
@ -36,13 +38,13 @@ def main(filename):
try:
hds = weboob.build_backend('hds')
except ModuleLoadError as e:
print >>sys.stderr, 'Unable to load "hds" module: %s' % e
print('Unable to load "hds" module: %s' % e, file=sys.stderr)
return 1
try:
db = sqlite.connect(database=filename, timeout=10.0)
except sqlite.OperationalError as err:
print >>sys.stderr, 'Unable to open %s database: %s' % (filename, err)
print('Unable to open %s database: %s' % (filename, err), file=sys.stderr)
return 1
sys.stdout.write('Reading database... ')
@ -50,7 +52,7 @@ def main(filename):
try:
results = db.execute('SELECT id, author FROM stories')
except sqlite.OperationalError as err:
print >>sys.stderr, 'fail!\nUnable to read database: %s' % err
print('fail!\nUnable to read database: %s' % err, file=sys.stderr)
return 1
stored = set()
@ -104,33 +106,33 @@ def main(filename):
if __name__ == '__main__':
if len(sys.argv) < 2:
print >>sys.stderr, 'Syntax: %s [--help] SQLITE_FILENAME' % sys.argv[0]
print('Syntax: %s [--help] SQLITE_FILENAME' % sys.argv[0], file=sys.stderr)
sys.exit(1)
if sys.argv[1] in ('-h', '--help'):
print 'Syntax: %s SQLITE_FILENAME' % sys.argv[0]
print ''
print 'Before running this software, please create the database with'
print 'this command:'
print ' $ cat scheme.sql | sqlite3 hds.sql'
print ''
print 'You can then run export.py with:'
print ' $ %s hds.sql ' % sys.argv[0]
print ''
print 'It fill the database with stories and authors information'
print 'fetched from histoires-de-sexe.net'
print ''
print 'You can next use SQL queries to find interesting stories, for'
print 'example:'
print ''
print '- To get all stories written by women'
print ' sqlite> SELECT s.id, s.title, s.category, a.name'
print ' FROM stories AS s LEFT JOIN authors AS a'
print ' WHERE a.name = s.author AND a.sex = 2;'
print '- To get all stories where it talks about bukkake'
print ' sqlite> SELECT s.id, s.title, s.category, a.name'
print ' FROM stories AS s LEFT JOIN authors AS a'
print ' WHERE a.name = s.author AND s.body LIKE \'%bukkake%\';'
print('Syntax: %s SQLITE_FILENAME' % sys.argv[0])
print('')
print('Before running this software, please create the database with')
print('this command:')
print(' $ cat scheme.sql | sqlite3 hds.sql')
print('')
print('You can then run export.py with:')
print(' $ %s hds.sql ' % sys.argv[0])
print('')
print('It fill the database with stories and authors information')
print('fetched from histoires-de-sexe.net')
print('')
print('You can next use SQL queries to find interesting stories, for')
print('example:')
print('')
print('- To get all stories written by women')
print(' sqlite> SELECT s.id, s.title, s.category, a.name')
print(' FROM stories AS s LEFT JOIN authors AS a')
print(' WHERE a.name = s.author AND a.sex = 2;')
print('- To get all stories where it talks about bukkake')
print(' sqlite> SELECT s.id, s.title, s.category, a.name')
print(' FROM stories AS s LEFT JOIN authors AS a')
print(' WHERE a.name = s.author AND s.body LIKE \'%bukkake%\';')
sys.exit(0)
sys.exit(main(sys.argv[1]))

View file

@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import resources.lib.test.common_test as common_xbmc
@ -7,7 +8,7 @@ import resources.lib.constants as constants
from resources.lib.actions import actions
print sys.argv
print(sys.argv)
if len(sys.argv) < 2:
actions[constants.DISPLAY_MENU]()._do()
else:

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
from . import constants
@ -52,7 +53,7 @@ class DisplayCollectionMenuAction(VideoobBaseAction):
common_xbmc.end_of_directory(False)
def add_videos(self, _video, backend):
print _video
print(_video)
video = self.videoobmc.get_video(_video, backend)
if video:
MenuItemVideo(video).add_to_menu()

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import xbmc
import xbmcgui
@ -41,7 +42,7 @@ def get_addon_dir():
def display_error(msg):
xbmc.executebuiltin("XBMC.Notification(%s, %s)" % (get_translation('30200').decode('utf-8'), msg))
print msg
print(msg)
print_exc(msg)

View file

@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from weboob.tools.application.base import Application
import os
@ -53,7 +54,7 @@ class Weboobmc(Application):
with open('/dev/null', 'w') as devnull:
process = subprocess.Popen(['which', executable], stdout=devnull)
if process.wait() != 0:
print 'Please install "%s"' % executable
print('Please install "%s"' % executable)
return False
return True

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import urllib
@ -33,11 +34,11 @@ def get_settings(key):
def display_error(error):
print "%s: %s" % ("ERROR", error)
print("%s: %s" % ("ERROR", error))
def display_info(msg):
print "%s: %s" % ("INFO", msg)
print("%s: %s" % ("INFO", msg))
def parse_params(paramStr):
@ -93,18 +94,18 @@ def create_param_url(paramsDic, quote_plus=False):
def add_menu_item(params={}):
print '%s => "%s"' % (params.get('name'), create_param_url(params))
print('%s => "%s"' % (params.get('name'), create_param_url(params)))
def add_menu_link(params={}):
print '[%s] %s (%s)' % (params.get('id'), params.get('name'), params.get('url'))
print('[%s] %s (%s)' % (params.get('id'), params.get('name'), params.get('url')))
#print params.get('itemInfoLabels')
#print params.get('c_items')
def end_of_directory(update=False):
print '******************************************************'
print('******************************************************')
def download_video(url, name, dir='./'):
print 'Downlaod a video %s from %s' % (name, url)
print('Downlaod a video %s from %s' % (name, url))

View file

@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from .base.weboobmc2 import Weboobmc
from weboob.capabilities.video import BaseVideo, CapVideo
@ -22,7 +23,7 @@ class Videoobmc(Weboobmc):
for _backend, video in self.weboob.do(self._do_complete, self.count, fields, 'search_videos', **kwargs):
yield video
except Exception as e:
print e
print(e)
def get_video(self, video, _backend):
backend = self.weboob.get_backend(_backend)

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os
@ -79,8 +80,8 @@ class VideoobWeb(Application):
def main(self, argv):
self.load_config()
self.weboob.load_backends(CapVideo)
print 'Web server created. Listening on http://%s:%s' % (
self.config.get('host'), int(self.config.get('port')))
print('Web server created. Listening on http://%s:%s' % (
self.config.get('host'), int(self.config.get('port'))))
srv = make_server(self.config.get('host'), int(self.config.get('port')), self.make_app)
srv.serve_forever()