Skip to content

Commit 6306080

Browse files
author
Olivier Poitrey
committed
Add python 3 compat
1 parent de60f2c commit 6306080

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

scanman/main.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
from kivy.app import App
4-
from kivy.lang import Builder
54
from kivy.uix.boxlayout import BoxLayout
65
from kivy.uix.image import Image
76
from kivy.core.image import ImageData
@@ -10,7 +9,6 @@
109
from kivy.properties import NumericProperty, ObjectProperty, BooleanProperty, StringProperty
1110
from kivy.uix.behaviors import ToggleButtonBehavior
1211
from kivy.graphics import Line, Color
13-
from StringIO import StringIO
1412
from img2pdf import pdfdoc
1513
from datetime import datetime
1614
import smtplib
@@ -21,6 +19,11 @@
2119

2220
from .scanner import Scanner
2321

22+
try:
23+
from StringIO import StringIO
24+
except:
25+
from io import StringIO
26+
2427

2528
class ScanMan(BoxLayout):
2629
scan_button = ObjectProperty(None)
@@ -113,18 +116,18 @@ def set_connected(state):
113116
self.scanner.connected(set_connected)
114117

115118
def on_connected(self, instance, value):
116-
print 'connected', value
119+
print('connected', value)
117120
self.reset_custom_status()
118121
self._update_status()
119122

120123
def on_ready(self, instance, value):
121-
print 'ready', value
124+
print('ready', value)
122125
if not self.scanning:
123126
self.reset_custom_status()
124127
self._update_status()
125128

126129
def on_scanning(self, instance, value):
127-
print 'scanning', value
130+
print('scanning', value)
128131
self._update_status()
129132

130133
def on_custom_status_text(self, instance, value):
@@ -165,14 +168,14 @@ def scan(self):
165168
self.reset_custom_status()
166169
self.scanning = True
167170
profile = self.settings['profiles'][self.ui.active_profile()]
168-
print 'scan with profile', profile.get('name')
171+
print('scan with profile', profile.get('name'))
169172

170173
pdf = pdfdoc()
171174
dpi = self.scanner.dev.resolution
172175

173176
def scan_processor(page_index, image):
174-
print 'processing page %d' % (page_index+1)
175-
self.custom_status_text = 'Processing page %d' % (page_index+1)
177+
print('processing page {}'.format(page_index+1))
178+
self.custom_status_text = 'Processing page {}'.format(page_index+1)
176179
self._update_preview(image)
177180
buf = StringIO()
178181
image.save(buf, format='JPEG', quality=75, optimize=True)
@@ -182,7 +185,7 @@ def scan_processor(page_index, image):
182185
buf.close()
183186

184187
def done():
185-
print 'processing document'
188+
print('processing document')
186189
self.custom_status_text = 'Processing document…'
187190
self._update_status()
188191
filename = datetime.now().strftime(self.settings.get('filename', '%Y%m%d-%H%M%S'))
@@ -193,7 +196,7 @@ def done():
193196
att = MIMEApplication(pdf.tostring(), _subtype='pdf')
194197
att.add_header('content-disposition', 'attachment', filename=('utf-8', '', filename + '.pdf'))
195198
msg.attach(att)
196-
print 'sending email', profile
199+
print('sending email', profile)
197200
self.custom_status_text = 'Sending email…'
198201
s = smtplib.SMTP(profile.get('smtp_server', self.settings.get('smtp_server', 'localhost')))
199202
if profile.get('smtp_tls', self.settings.get('smtp_tls', False)):
@@ -215,7 +218,7 @@ def cancelled():
215218
self.scanner.scan(scan_processor, done, cancelled)
216219

217220
def cancel(self):
218-
print 'cancelling'
221+
print('cancelling')
219222
self.scanning = False
220223
self.scanner.cancel()
221224

@@ -224,7 +227,7 @@ def main():
224227
try:
225228
settings = yaml.safe_load(open(sys.argv[1]))
226229
except:
227-
print "Syntax: scanman <path/to/config.yaml>"
230+
print('Syntax: scanman <path/to/config.yaml>')
228231
exit(1)
229232
ScanManApp(settings).run()
230233

scanman/scanner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import sane
22
import threading
3-
from Queue import Queue, Empty
43
import time
54

5+
try:
6+
from Queue import Queue, Empty
7+
except:
8+
from queue import Queue, Empty
9+
610

711
class Scanner(object):
812
PAGE_LOADED = 82
@@ -116,7 +120,6 @@ def scan():
116120
q.join()
117121
done()
118122
else:
119-
print e
120123
cancelled()
121124
self.scanning = False
122125
return

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
setup(
33
name='scanman',
44
packages=['scanman'],
5-
version='0.3',
5+
version='0.5',
66
description='A ScanSnap manager for Raspbery Pi',
77
author='Olivier Poitrey',
88
author_email='[email protected]',
99
url='https://github.com/rs/scanman',
10-
download_url='https://github.com/rs/scanman/tarball/0.3',
10+
download_url='https://github.com/rs/scanman/tarball/0.5',
1111
install_requires=['kivy', 'python-sane', 'img2pdf', 'pyyaml'],
1212
package_data={'scanman': ['*.kv']},
1313
entry_points={'console_scripts': [

0 commit comments

Comments
 (0)