示例#1
0
 def process_attribs_change(self, filename, context):
     photo = Photo.query.filter_by(file=filename).first()
     if photo != None:
         photo.owner = get_file_owner(filename).get_username()
         photo.shared = is_file_shared(filename)
         db.session.commit()
     else:
         self.process_updated_file(filename, context)
示例#2
0
 def process_updated_file(self, filename, context):
     if not self.is_hidden(filename) and get_mime_type(filename).startswith("image/"):
         # Get modification time
         f = open(filename, "rb")
         tags = EXIF.process_file(f, stop_tag="DateTimeOriginal")
         if "EXIF DateTimeOriginal" in tags:
             date_as_string = tags["EXIF DateTimeOriginal"].values
             date = datetime.datetime.strptime(date_as_string, "%Y:%m:%d %H:%M:%S")
         else:
             date = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
         f.close()
         # Update or write new
         photo = Photo.query.filter_by(file=filename).first()
         now = datetime.datetime.now()
         owner = get_file_owner(filename).get_username()
         shared = is_file_shared(filename)
         if photo != None:
             photo.date = date
             photo.lastModified = now
             photo.owner = owner
             photo.shared = shared
             db.session.commit()
         else:
             photo = Photo(filename, os.path.basename(filename), date, datetime.datetime.now(), owner, shared)
             db.session.add(photo)
             db.session.commit()
             # Add to album
             context_path = "/var/nublic/data/" + context[:-1]
             (parent, _basename) = os.path.split(filename)
             (p_parent, p_basename) = os.path.split(parent)
             (_p_p_parent, p_p_basename) = os.path.split(p_parent)
             if context_path == parent:
                 album = None
             elif context_path == p_parent:
                 album = p_basename
             else:
                 album = p_p_basename + "/" + p_basename
             if album != None:
                 ab = get_or_create_album(album)
                 relation = PhotoAlbum(ab.id, photo.id)
                 db.session.add(relation)
                 db.session.commit()
示例#3
0
 def update_attribs(self, song):
     song.owner = get_file_owner(song.file.encode('utf-8')).get_username()
     song.shared = is_file_shared(song.file.encode('utf-8'))
     db.session.commit()