コード例 #1
0
  def maybe_get_back_href(self, path):
    """
    Given a nullable path name, turns it into a href that can be used
    to write an anchor tag pointing to a HTML file. If path
    is None, propagates the None by returning it.

    Args:
      path the path name, or None if it is not applicable.
    """
    if path is None:
     return None
    else:
      return directory_name_to_html_file_name(path)
コード例 #2
0
  def try_create_jpeg_picture(self, path, name):
    """
    Given a path and the name of a file ending in .jpg, tries to create
    a JpegPicture object out of it.

    Args:
      path the path to the directory the file is in.
      name the name of the file.

    Returns:
      A JpegPicture object, if creating it was successful. None if creating
      the JpegPicture failed for some reason that does not warrant crashing
      the program.

    Raises:
      Any exception raised when trying to extract IPTC information from the
      JPEG, that is not an IOError or an exception with the message 
      'No IPTC data found.' In those two cases, simply skips the file and
      prints a message saying so.
    """
    full_jpeg_name = os.path.join(path, name)
    try:
      return JpegPicture(name,
        directory_name_to_html_file_name(path),
        self.iptc_info_constructor(full_jpeg_name),
          self.lookup_table)
    except IOError:
      print "I was unable to open the file ", name, " for some reason"
      print "Maybe it's corrupted?"
      print "Skipping it..."
      return None
    except Exception as possible_iptc_exception:
      if str(possible_iptc_exception) == 'No IPTC data found.':
        print "I was unable to get IPTC data from the file %s" % name
        print "Skipping it..."
        return None
      else:
        raise possible_iptc_exception # Some other exception