diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-01-14 16:34:44 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-01-15 10:25:12 +0900 |
commit | 900386ad4615a3dbbc04501ef24c5a43385c6078 (patch) | |
tree | e7c547f76f2100bd99be8962fe7a07c1a64d1c34 /konq-plugins | |
parent | 8293cbe18989cabc30375754087091a53a78b3ee (diff) | |
download | tdeaddons-900386ad4615a3dbbc04501ef24c5a43385c6078.tar.gz tdeaddons-900386ad4615a3dbbc04501ef24c5a43385c6078.zip |
Drop python2 support.r14.1.0
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'konq-plugins')
-rwxr-xr-x | konq-plugins/imagerotation/exif.py | 47 | ||||
-rwxr-xr-x | konq-plugins/imagerotation/orient.py | 36 |
2 files changed, 41 insertions, 42 deletions
diff --git a/konq-plugins/imagerotation/exif.py b/konq-plugins/imagerotation/exif.py index 60fce74..d96759b 100755 --- a/konq-plugins/imagerotation/exif.py +++ b/konq-plugins/imagerotation/exif.py @@ -97,7 +97,7 @@ EXIF_TAGS={ 0x010F: ('Make', ), 0x0110: ('Model', ), 0x0111: ('StripOffsets', ), - 0x0112: ('Qt::Orientation', ), + 0x0112: ('Orientation', ), 0x0115: ('SamplesPerPixel', ), 0x0116: ('RowsPerStrip', ), 0x0117: ('StripByteCounts', ), @@ -631,7 +631,7 @@ MAKERNOTE_CANON_TAG_0x004={ def s2n_motorola(str): x=0 for c in str: - x=(long(x) << 8) | ord(c) + x=(int(x) << 8) | ord(c) return x # extract multibyte integer in Intel format (big endian) @@ -707,7 +707,7 @@ class EXIF_header: val=s2n_motorola(slice) # Sign extension ? if signed: - msb=1L << (8*length-1) + msb=1 << (8*length-1) if val & msb: val=val-(msb << 1) return val @@ -750,8 +750,7 @@ class EXIF_header: field_type=self.s2n(entry+2, 2) if not 0 < field_type < len(FIELD_TYPES): # unknown field type - raise ValueError, \ - 'unknown type %d in tag 0x%04X' % (field_type, tag) + raise ValueError('unknown type %d in tag 0x%04X' % (field_type, tag)) typelen=FIELD_TYPES[field_type][0] count=self.s2n(entry+4, 4) offset=entry+8 @@ -807,8 +806,8 @@ class EXIF_header: values, field_offset, count*typelen) if self.debug: - print ' %s: %s' % (tag_name, - repr(self.tags[ifd_name+' '+tag_name])) + print(' %s: %s' % (tag_name, + repr(self.tags[ifd_name+' '+tag_name]))) # extract uncompressed TIFF thumbnail (like pulling teeth) # we take advantage of the pre-existing layout in the thumbnail IFD as @@ -920,7 +919,7 @@ class EXIF_header: for i in (('MakerNote Tag 0x0001', MAKERNOTE_CANON_TAG_0x001), ('MakerNote Tag 0x0004', MAKERNOTE_CANON_TAG_0x004)): if self.debug: - print ' SubMakerNote BitSet for ' +i[0] + print(' SubMakerNote BitSet for ' +i[0]) self.canon_decode_tag(self.tags[i[0]].values, i[1]) return @@ -937,7 +936,7 @@ class EXIF_header: else: val=value[i] if self.debug: - print ' '+name+':', val + print(' '+name+':', val) self.tags['MakerNote '+name]=val # process an image file (expects an open file object) @@ -973,7 +972,7 @@ def process_file(file, debug=0, noclose=0): # deal with the EXIF info we found if debug: - print {'I': 'Intel', 'M': 'Motorola'}[endian], 'format' + print({'I': 'Intel', 'M': 'Motorola'}[endian], 'format') hdr=EXIF_header(file, endian, offset, debug) ifd_list=hdr.list_IFDs() ctr=0 @@ -986,7 +985,7 @@ def process_file(file, debug=0, noclose=0): else: IFD_name='IFD %d' % ctr if debug: - print ' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i) + print(' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i)) hdr.tags['Exif Offset'] = offset hdr.tags['Exif Endian'] = endian hdr.tags[IFD_name+' IFDOffset'] = i @@ -995,28 +994,28 @@ def process_file(file, debug=0, noclose=0): exif_off=hdr.tags.get(IFD_name+' ExifOffset') if exif_off: if debug: - print ' EXIF SubIFD at offset %d:' % exif_off.values[0] + print(' EXIF SubIFD at offset %d:' % exif_off.values[0]) hdr.dump_IFD(exif_off.values[0], 'EXIF') # Interoperability IFD contained in EXIF IFD #intr_off=hdr.tags.get('EXIF SubIFD InteroperabilityOffset') intr_off=hdr.tags.get('EXIF InteroperabilityOffset') if intr_off: if debug: - print ' EXIF Interoperability SubSubIFD at offset %d:' \ - % intr_off.values[0] + print(' EXIF Interoperability SubSubIFD at offset %d:' \ + % intr_off.values[0]) hdr.dump_IFD(intr_off.values[0], 'EXIF Interoperability', dict=INTR_TAGS) # deal with MakerNote contained in EXIF IFD - if hdr.tags.has_key('EXIF MakerNote'): + if 'EXIF MakerNote' in hdr.tags: if debug: - print ' EXIF MakerNote SubSubIFD at offset %d:' \ - % intr_off.values[0] + print(' EXIF MakerNote SubSubIFD at offset %d:' \ + % intr_off.values[0]) hdr.decode_maker_note() # GPS IFD gps_off=hdr.tags.get(IFD_name+' GPSInfoOffset') if gps_off: if debug: - print ' GPS SubIFD at offset %d:' % gps_off.values[0] + print(' GPS SubIFD at offset %d:' % gps_off.values[0]) hdr.dump_IFD(gps_off.values[0], 'GPS', dict=GPS_TAGS) ctr+=1 @@ -1035,7 +1034,7 @@ def process_file(file, debug=0, noclose=0): # Sometimes in a TIFF file, a JPEG thumbnail is hidden in the MakerNote # since it's not allowed in a uncompressed TIFF IFD - if not hdr.tags.has_key('JPEGThumbnail'): + if 'JPEGThumbnail' not in hdr.tags: thumb_off=hdr.tags.get('MakerNote JPEGThumbnail') if thumb_off: file.seek(offset+thumb_off.values[0]) @@ -1050,21 +1049,21 @@ if __name__ == '__main__': import sys if len(sys.argv) < 2: - print 'Usage: %s files...\n' % sys.argv[0] + print('Usage: %s files...\n' % sys.argv[0]) sys.exit(0) for filename in sys.argv[1:]: try: file=open(filename, 'rb') except: - print filename, 'unreadable' - print + print(filename, 'unreadable') + print() continue - print filename+':' + print(filename+':') # data=process_file(file, 1) # with debug info data=process_file(file, 1) if not data: - print 'No EXIF information found' + print('No EXIF information found') continue # x=data.keys() 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) |