def read_info(outputdir, get_cover):
 os.chdir(outputdir)
 (pdfinfo, pdftoppm) = get_tools()
 ans = {}
 try:
  raw = subprocess.check_output([pdfinfo, '-enc', 'UTF-8', 'src.pdf'])
 except subprocess.CalledProcessError as e:
  prints(('pdfinfo errored out with return code: %d' % e.returncode))
  return None
 try:
  info_raw = raw.decode('utf-8')
 except UnicodeDecodeError:
  prints('pdfinfo returned no UTF-8 data')
  return None
 for line in info_raw.splitlines():
  if (u':' not in line):
   continue
  (field, val) = line.partition(u':')[::2]
  val = val.strip()
  if (field and val):
   ans[field] = val.strip()
 try:
  raw = subprocess.check_output([pdfinfo, '-meta', 'src.pdf']).strip()
 except subprocess.CalledProcessError as e:
  prints(('pdfinfo errored out with return code: %d' % e.returncode))
 parts = re.split('^Metadata:', raw, 1, flags=re.MULTILINE)
 if (len(parts) > 1):
  ans['xmp_metadata'] = parts[1]
 elif raw:
  ans['xmp_metadata'] = raw
 if get_cover:
  try:
   subprocess.check_call([pdftoppm, '-singlefile', '-jpeg', '-cropbox', 'src.pdf', 'cover'])
  except subprocess.CalledProcessError as e:
   prints(('pdftoppm errored out with return code: %d' % e.returncode))
 return ans

def read_info ( outputdir , get_cover ) : os . chdir ( outputdir ) ( pdfinfo , pdftoppm ) = get_tools ( ) ans = { } try : raw = subprocess . check_output ( [ pdfinfo , '-enc' , 'UTF-8' , 'src.pdf' ] ) except subprocess . CalledProcessError as e : prints ( ( 'pdfinfo errored out with return code: %d' % e . returncode ) ) return None try : info_raw = raw . decode ( 'utf-8' ) except UnicodeDecodeError : prints ( 'pdfinfo returned no UTF-8 data' ) return None for line in info_raw . splitlines ( ) : if ( u':' not in line ) : continue ( field , val ) = line . partition ( u':' ) [ : : 2 ] val = val . strip ( ) if ( field and val ) : ans [ field ] = val . strip ( ) try : raw = subprocess . check_output ( [ pdfinfo , '-meta' , 'src.pdf' ] ) . strip ( ) except subprocess . CalledProcessError as e : prints ( ( 'pdfinfo errored out with return code: %d' % e . returncode ) ) parts = re . split ( '^Metadata:' , raw , 1 , flags = re . MULTILINE ) if ( len ( parts ) > 1 ) : ans [ 'xmp_metadata' ] = parts [ 1 ] elif raw : ans [ 'xmp_metadata' ] = raw if get_cover : try : subprocess . check_call ( [ pdftoppm , '-singlefile' , '-jpeg' , '-cropbox' , 'src.pdf' , 'cover' ] ) except subprocess . CalledProcessError as e : prints ( ( 'pdftoppm errored out with return code: %d' % e . returncode ) ) return ans
read measurement info from a file .