-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstep_jpeg_verify.py
executable file
·91 lines (57 loc) · 2.01 KB
/
step_jpeg_verify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Jpeg Verification
Verify the JPEG files we created from tiff files are valid
Command line:
needs: process_id, and tifffolder
optional: auto_complete, step_id, correction_step_name
Relies on steps:
none
Example run :
In Goobi:
/opt/digiverso/goobi/scripts/bdlss/step_jperg_verify.py process_id={processid} tiff_path={tifpath}
From command line:
sudo -u tomcat6 ./step_jpeg_verify.py process_id=75 tiff_path=/opt/digiverso/goobi/metadata/75/images/healedanw_222_FFFFF_tif debug=True
'''
from goobi.goobi_step import Step
from jhove.jhove import Jhove
class Step_Jpeg_Verify(Step):
def setup( s ):
s.name = "JPEG Verify"
s.config_main_section = "jpeg_verify" # Info for this particular step
s.essential_config_sections = set( ['jhove'] )
s.essential_commandlines = {
"process_id":"number",
"tiff_path":"folder"
}
def step( self ):
error = None
# Get jpeg path and check
jpeg_path = self.command_line.tiff_path.replace( '_tif', '_jpg' )
if self.checkFolder( jpeg_path ) == None :
jhove = Jhove( self.config.jhove.file, self.config.jhove.conf )
details = jhove.checkFolder( jpeg_path, Jhove.FILETYPE.JPEG )
files_failed = []
for file in details:
if not details[file]['ok']:
files_failed.append( file )
if files_failed:
# Create error message
error = "There was a problem with " + str( len( files_failed ) ) + " jpeg files. Details follow. \n"
for file in files_failed:
error += 'Jpeg "' + file + '" failed'
error += ", " + details[file]['status']
messages = []
for message in details[file]['messages'] :
messages.append( '"' + message + '"' )
if messages:
error += " - " + ", ".join( messages )
error += "\n"
# self.error( error )
else:
error = "Jpeg folder " + jpeg_path + " does not exist"
return error
if __name__ == '__main__' :
import config_ini
Step_Jpeg_Verify( config_ini.file ).begin( )