Commit 74a4ef67 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧

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.
parent d2265630
......@@ -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()
......
......@@ -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":
......
......@@ -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]))
#!/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:
......
# -*- 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()
......
# -*- 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)
......
#!/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
......
# -*- 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))
#!/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)
......
......@@ -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()
......
......@@ -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 hashlib
import sys
......@@ -92,13 +93,13 @@ class Tile(object):
self.map.append(pxls)
def display(self):
print '-' * (len(self.map) * 2 + 2)
print('-' * (len(self.map) * 2 + 2))
for y in xrange(len(self.map[0])):
sys.stdout.write('|')
for x in xrange(len(self.map)):
sys.stdout.write('%s' % ('XX' if self.map[x][y] else ' '))
print '|'
print '-' * (len(self.map) * 2 + 2)
print('|')
print('-' * (len(self.map) * 2 + 2))
def checksum(self):
s = ''
......@@ -113,9 +114,9 @@ class Tile(object):
try:
return self.hash[checksum]
except KeyError:
print 'Unable te resolve:'
print('Unable te resolve:')
self.display()
print 'hash: %s' % checksum
print('hash: %s' % checksum)
raise CaptchaError()
......@@ -175,11 +176,11 @@ class Decoder(object):
checksum = tile.checksum()
if checksum in self.hash:
print 'Skipping %s' % self.hash[checksum]
print('Skipping %s' % self.hash[checksum])
continue
tile.display()
print 'Checksum: %s' % checksum
print('Checksum: %s' % checksum)
ntry = 2
while ntry:
sys.stdout.write('Enter the letter: ')
......@@ -187,9 +188,9 @@ class Decoder(object):
ntry -= 1
if len(l) != 1:
print 'Error: please enter only one letter'
print('Error: please enter only one letter')
elif l in self.hash.itervalues():
print 'Warning! This letter has already been catched!'
print('Warning! This letter has already been catched!')
else:
ntry = 0
......@@ -200,13 +201,13 @@ class Decoder(object):
while True:
self.process()
except KeyboardInterrupt:
print ''
print 'hash = {'
print('')
print('hash = {')
l = sorted(self.hash.iteritems(), key=lambda (k,v): (v,k))
for hash, value in l:
print ' \'%s\': %s' % (hash, value)
print(' \'%s\': %s' % (hash, value))
print '}'
print('}')
if __name__ == '__main__':
d = Decoder()
......
......@@ -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
from random import randint
......@@ -93,7 +94,7 @@ class ProfilesWalker(Optimization):
self.profiles_queue.add(id)
return
except Exception as e:
print e
print(e)
finally:
if self.view_cron is not None:
self.view_cron = self.sched.schedule(randint(5, 10), self.view_profile)
......@@ -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
from weboob.tools.browser import BrowserUnavailable
from weboob.capabilities.dating import Optimization
......@@ -45,5 +46,5 @@ class Visibility(Optimization):
with self.browser:
self.browser.login()
except BrowserUnavailable as e:
print str(e)
print(str(e))
pass
......@@ -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
from weboob.tools.browser import Page, BrowserIncorrectPassword
import urllib2
......@@ -121,4 +122,4 @@ class AuthenticationPage(Page):
def print_cookies(self):
for c in self.browser._ua_handlers["_cookies"].cookiejar:
print "%s : %s" % (c.name, c.value)
print("%s : %s" % (c.name, c.value))
......@@ -17,6 +17,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 re
from decimal import Decimal
......@@ -217,8 +219,8 @@ class CardsPage(Page):
try:
t.id = t.unique_id(seen)
except UnicodeEncodeError:
print t
print t.label
print(t)
print(t.label)
raise
yield t
......
......@@ -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
from weboob.tools.mech import ClientForm
ControlNotFoundError = ClientForm.ControlNotFoundError
......@@ -73,7 +75,7 @@ class VideoPage(Page):
obj = self.parser.select(self.document.getroot(), 'meta[name=available]', 1)
if obj is not None:
value = obj.attrib['content']
print value
print(value)
m = re.match('(\d\d)-(\d\d)-(\d\d\d\d)\s*(\d\d):(\d\d)', value)
if not m:
raise BrokenPageError('Unable to parse datetime: %r' % value)
......
......@@ -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 urllib
from weboob.tools.browser import Browser, BrowserIncorrectPassword, BrowserUnavailable,\
......@@ -149,7 +151,7 @@ class GDCVaultBrowser(Browser):
return self.page.iter_videos()
def latest_videos(self):
print "browser:latest_videos()"
print("browser:latest_videos()")
#self.home()
self.location('/free')
assert self.is_on_page(IndexPage)
......
......@@ -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
import urllib
import mechanize
......@@ -85,7 +86,7 @@ class HelloBank(Browser):
accounts = self.page.get_accounts()
if len(accounts) == 0:
print 'no accounts'
print('no accounts')
# oops, no accounts? check if we have not exhausted the allowed use
# of this password
for img in self.document.getroot().cssselect('img[align="middle"]'):
......
......@@ -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 decimal import Decimal
......@@ -66,7 +67,7 @@ class AccountsList(Page):
l.append(account)
if len(l) == 0:
print 'no accounts'
print('no accounts')
# oops, no accounts? check if we have not exhausted the allowed use
# of this password
for img in self.document.getroot().cssselect('img[align="middle"]'):
......
......@@ -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
from random import randint
......@@ -100,7 +101,7 @@ class ProfilesWalker(Optimization):
self.profiles_queue.add(id)
return
except Exception as e:
print e
print(e)
finally:
if self.view_cron is not None:
self.view_cron = self.sched.schedule(randint(5, 10), self.view_profile)
......@@ -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 hashlib
......@@ -133,7 +134,7 @@ class Tile(object):
raise TileError('Tile not found ' + sum, self)
def display(self):
print self.checksum()
print(self.checksum())
#im = Image.new('RGB', (24, 23))
#im.putdata(self.map)
#im.save('/tmp/%s.png' % self.checksum())
......@@ -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 re
from weboob.browser2.page import JsonPage, HTMLPage, method
......@@ -142,7 +144,7 @@ class DeparturesPage2(HTMLPage):
form['moiHoraire'] = '%s|%s' % (date.month, date.year)
form['heureHoraire'] = date.hour
form['minuteHoraire'] = date.minute
print form
print(form)
form.submit()
......
......@@ -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 argparse
import subprocess
import datetime
......@@ -50,11 +52,11 @@ def write(target, contents):
if not os.path.isdir(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
if os.path.exists(target):
print >>sys.stderr, "%s already exists." % target
print("%s already exists." % target, file=sys.stderr)
sys.exit(4)
with codecs.open(target, mode='w', encoding='utf-8') as f:
f.write(contents)
print 'Created %s' % target