summaryrefslogtreecommitdiffstats
path: root/konq-plugins/imagerotation/orient.py
diff options
context:
space:
mode:
Diffstat (limited to 'konq-plugins/imagerotation/orient.py')
-rwxr-xr-xkonq-plugins/imagerotation/orient.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/konq-plugins/imagerotation/orient.py b/konq-plugins/imagerotation/orient.py
index 8db06ad..f7a0047 100755
--- a/konq-plugins/imagerotation/orient.py
+++ b/konq-plugins/imagerotation/orient.py
@@ -13,42 +13,42 @@ def compose(delta, old):
def deg2o(d):
map={90:6, 270:8, 180:3}
- if map.has_key(d):
+ if d in map:
return map[d]
else:
return 0
if len(sys.argv) < 2:
- print 'Usage: %s [[+]orientnum] file\n' % sys.argv[0]
+ print('Usage: %s [[+]orientnum] file\n' % sys.argv[0])
sys.exit(1)
try:
if len(sys.argv) == 2:
filename=sys.argv[1]
- file=open(filename, "r");
+ file=open(filename, 'rb');
else:
filename=sys.argv[2]
mod=sys.argv[1]
fd = os.open(filename, os.O_RDWR)
- file=os.fdopen(fd,'r')
+ file=os.fdopen(fd,'rb')
# check file exists and is readable
file.read(1)
file.seek(0,0)
except:
- print 'Cannot open', filename
+ print('Cannot open', filename)
sys.exit(1)
tags=exif.process_file(file,0,1)
if not tags:
- print 'no EXIF information in', filename
+ print('no EXIF information in', filename)
sys.exit(1)
-if not tags.has_key('Exif Offset') \
- or not tags.has_key('Image Qt::Orientation'):
- print 'cannot get orientation info in', filename
+if 'Exif Offset' not in tags \
+ or 'Image Orientation' not in tags:
+ print('cannot get orientation info in', filename)
sys.exit(1)
exifp = tags['Exif Offset']
endian = tags['Exif Endian']
-tagp = tags['Image Qt::Orientation'].field_offset
+tagp = tags['Image Orientation'].field_offset
orientp = exifp + tagp
@@ -59,11 +59,11 @@ file.seek(orientp)
o = ord(file.read(1))
if o < 1 or o > 8:
- print 'orientation out of range', o
+ print('orientation out of range', o)
sys.exit(1)
if len(sys.argv) == 2:
- print 'orientation is', o
+ print('orientation is', o)
sys.exit(0)
try:
@@ -74,18 +74,18 @@ try:
elif deg2o(deltao) != 0:
newo = compose(deg2o(deltao), o)
else:
- print 'cannot understand orientation modification', mod
+ print('cannot understand orientation modification', mod)
sys.exit(1) # it will still hit the except ... how to fix?
else:
newo = int(mod)
except:
- print 'expected numeric orientation and got',mod
+ print('expected numeric orientation and got',mod)
sys.exit(1)
if newo < 1 or newo > 8:
newo = deg2o(newo)
if newo == 0:
- print 'cannot understand orientation', deltao
+ print('cannot understand orientation', deltao)
sys.exit(1)
os.lseek(fd,orientp,0)
@@ -93,12 +93,12 @@ os.write(fd,chr(newo))
# Thumbnail orientation :
thumb_ifdp = 0
-if tags.has_key('Thumbnail Qt::Orientation'):
- thumb_tagp = tags['Thumbnail Qt::Orientation'].field_offset
+if 'Thumbnail Orientation' in tags:
+ thumb_tagp = tags['Thumbnail Orientation'].field_offset
thumb_orientp = exifp + thumb_tagp
if endian == 'M': # MM byte order
thumb_orientp += 1
os.lseek(fd,thumb_orientp,0)
os.write(fd,chr(newo))
-print 'orientation changed from', o, 'to', newo
+print('orientation changed from', o, 'to', newo)