def scan_album(album): fotos = list_album(album) names = os.listdir(os.path.join(settings.PHOTOS_DIR, album.full_path)) names.sort() for name in names: filepath = os.path.join(settings.PHOTOS_DIR, album.full_path, name) if name[0] == ".": continue entity = fotos.get(name, None) if entity is not None and entity.is_lost: entity.found(album) if os.path.isdir(filepath): # album if entity is None: entity = fEs.entity( { "type": "album", "path": album.full_path, "name": name, "random": random.random(), "visibility": ["hidden"], } ) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() scan_album(entity) elif os.path.splitext(name)[1][1:].lower() in extensions: # photo entity = fotos.get(name, None) if entity is None: entity = fEs.entity( { "type": "foto", "path": album.full_path, "name": name, "random": random.random(), "visibility": ["world"], } ) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() for entity in fotos.values(): if entity.name not in names: entity.lost(album)
def scan_album(album): fotos = list_album(album) album_path = os.path.join(settings.PHOTOS_DIR, album.full_path) names = sorted(os.listdir(album_path)) for name in names: filepath = os.path.join(album_path, name) if name[0] == '.': continue entity = fotos.get(name, None) if entity is not None and entity.is_lost: entity.found(album) if os.path.isdir(filepath): # album if entity is None: entity = fEs.entity({ 'type': 'album', 'path': album.full_path, 'name': name, 'random': random.random(), 'visibility': ['hidden'] }) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() scan_album(entity) elif os.path.splitext(name)[1][1:].lower() in extensions: # photo entity = fotos.get(name, None) if entity is None: entity = fEs.entity({ 'type': 'foto', 'path': album.full_path, 'name': name, 'random': random.random(), 'visibility': ['world'] }) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() for entity in fotos.values(): if entity.name not in names: entity.lost(album)
def scan_album(album): fotos = list_album(album) album_path = os.path.join(settings.PHOTOS_DIR, album.full_path) names = sorted(os.listdir(album_path)) for name in names: filepath = os.path.join(album_path, name) if name[0] == '.': continue entity = fotos.get(name, None) if entity is not None and entity.is_lost: entity.found(album) if os.path.isdir(filepath): # album if entity is None: entity = fEs.entity({ 'type': 'album', 'path': album.full_path, 'name': name, 'random': random.random(), 'visibility': ['hidden']}) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() scan_album(entity) elif os.path.splitext(name)[1][1:].lower() in extensions: # photo entity = fotos.get(name, None) if entity is None: entity = fEs.entity({ 'type': 'foto', 'path': album.full_path, 'name': name, 'random': random.random(), 'visibility': ['world']}) entity.update_metadata(album, save=False) entity.save() elif entity.update_metadata(album, save=False): entity.save() for entity in fotos.values(): if entity.name not in names: entity.lost(album)
def scan_fotos(): album = fEs.by_path('') if album is None: album = fEs.entity({ 'type': 'album', 'name': '', 'path': None, 'random': random.random(), 'title': 'Karpe Noktem fotoalbum', 'description': "De fotocollectie van Karpe Noktem", 'visibility': ['world'] }) album.update_metadata(None) album.save() elif album.update_metadata(None): album.save() scan_album(album)
def scan_fotos(): album = fEs.by_path('') if album is None: album = fEs.entity({ 'type': 'album', 'name': '', 'path': None, 'random': random.random(), 'title': 'Karpe Noktem fotoalbum', 'description': "De fotocollectie van Karpe Noktem", 'visibility': ['world']}) album.update_metadata(None) album.save() elif album.update_metadata(None): album.save() scan_album(album) return {'success': True}
def scan_fotos(): album = fEs.by_path("") if album is None: album = fEs.entity( { "type": "album", "name": "", "path": None, "random": random.random(), "title": "Karpe Noktem fotoalbum", "description": "De fotocollectie van Karpe Noktem", "visibility": ["world"], } ) album.update_metadata(None) album.save() elif album.update_metadata(None): album.save() scan_album(album) return {"success": True}
def fotoadmin_create_event(daan, date, name, humanName): if not re.match('^20\d{2}-\d{2}-\d{2}$', date): return {'error': 'Invalid date'} if not re.match('^[a-z0-9-]{3,64}$', name): return {'error': 'Invalid name'} event = date + '-' + name path = os.path.join(settings.PHOTOS_DIR, event) if os.path.isdir(path): return {'error': 'Event already exists'} os.mkdir(path, 0o775) os.chown(path, pwd.getpwnam('fotos').pw_uid, grp.getgrnam('fotos').gr_gid) album = fEs.entity({ 'type': 'album', 'path': '', 'name': event, 'random': random.random(), 'visibility': ['hidden'], 'title': humanName}) album.update_metadata(album.get_parent(), save=False) album.save() return {'success': True}
def fotoadmin_create_event(daan, date, name, humanName): if not re.match('^20\d{2}-\d{2}-\d{2}$', date): return {'error': 'Invalid date'} if not re.match('^[a-z0-9-]{3,64}$', name): return {'error': 'Invalid name'} event = date + '-' + name path = os.path.join(settings.PHOTOS_DIR, event) if os.path.isdir(path): return {'error': 'Event already exists'} os.mkdir(path, 0o775) os.chown(path, pwd.getpwnam('fotos').pw_uid, grp.getgrnam('fotos').gr_gid) album = fEs.entity({ 'type': 'album', 'path': '', 'name': event, 'random': random.random(), 'visibility': ['hidden'], 'title': humanName }) album.update_metadata(album.get_parent(), save=False) album.save() return {'success': True}
def main(): fEs.ensure_indices() creds = settings.PHOTOS_MYSQL_SECRET dc = MySQLdb.connect(creds[0], user=creds[1], passwd=creds[2], db=creds[3]) c = dc.cursor() if fEs.by_path('') is None: root = fEs.entity({ 'type': 'album', 'path': None, 'name': '', 'title': 'Karpe Noktem fotoalbum', 'description': "De fotocollectie van Karpe Noktem", 'random': random.random(), 'visibility': ['world'] }) root.update_metadata(None, save=False) root.save() print('albums') c.execute("SELECT id, name, path, humanname, visibility, description " + "FROM fa_albums ORDER BY path") for oldId, name, path, humanName, visibility, description in c.fetchall(): if path and not path.endswith('/'): continue if fEs.by_oldId('album', oldId) is not None: continue data = { 'type': 'album', 'oldId': oldId, 'path': path.strip('/'), 'name': name, 'title': humanName, 'description': description, 'random': random.random() } if visibility == 'lost': visibility = [] data['lost'] = True elif visibility == 'deleted': visibility = [] else: visibility = [visibility] data['visibility'] = visibility album = fEs.entity(data) album.update_metadata(album.get_parent(), save=False) album.save() print('fotos') c.execute("SELECT id, name, path, visibility, rotation FROM fa_photos") for oldId, name, path, visibility, rotation in c.fetchall(): if fEs.by_oldId('foto', oldId) is not None: continue data = { 'type': 'foto', 'oldId': oldId, 'path': path.strip('/'), 'name': name, 'random': random.random(), 'rotation': rotation } if visibility == 'lost': visibility = [] data['lost'] = True elif visibility == 'deleted': visibility = [] else: visibility = [visibility] data['visibility'] = visibility foto = fEs.entity(data) foto.update_metadata(foto.get_parent(), save=False) foto.save() print('tags') c.execute("SELECT photo_id, username FROM fa_tags") for oldId, username in c.fetchall(): foto = fEs.by_oldId('foto', oldId) if foto is None: continue user = Es.by_name(username) if user is None: continue if 'tags' not in foto._data: foto._data['tags'] = [] if user._id not in foto._data['tags']: foto._data['tags'].append(user._id) foto.save() print('done')
def main(): fEs.ensure_indices() creds = settings.PHOTOS_MYSQL_SECRET dc = MySQLdb.connect(creds[0], user=creds[1], passwd=creds[2], db=creds[3]) c = dc.cursor() if fEs.by_path('') is None: root = fEs.entity({ 'type': 'album', 'path': None, 'name': '', 'title': 'Karpe Noktem fotoalbum', 'description': "De fotocollectie van Karpe Noktem", 'random': random.random(), 'visibility': ['world']}) root.update_metadata(None, save=False) root.save() print 'albums' c.execute("SELECT id, name, path, humanname, visibility, description " + "FROM fa_albums ORDER BY path") for oldId, name, path, humanName, visibility, description in c.fetchall(): if path and not path.endswith('/'): continue if fEs.by_oldId('album', oldId) is not None: continue data = {'type': 'album', 'oldId': oldId, 'path': path.strip('/'), 'name': name, 'title': humanName, 'description': description, 'random': random.random()} if visibility == 'lost': visibility = [] data['lost'] = True elif visibility == 'deleted': visibility = [] else: visibility = [visibility] data['visibility'] = visibility album = fEs.entity(data) album.update_metadata(album.get_parent(), save=False) album.save() print 'fotos' c.execute("SELECT id, name, path, visibility, rotation FROM fa_photos") for oldId, name, path, visibility, rotation in c.fetchall(): if fEs.by_oldId('foto', oldId) is not None: continue data = {'type': 'foto', 'oldId': oldId, 'path': path.strip('/'), 'name': name, 'random': random.random(), 'rotation': rotation} if visibility == 'lost': visibility = [] data['lost'] = True elif visibility == 'deleted': visibility = [] else: visibility = [visibility] data['visibility'] = visibility foto = fEs.entity(data) foto.update_metadata(foto.get_parent(), save=False) foto.save() print 'tags' c.execute("SELECT photo_id, username FROM fa_tags") for oldId, username in c.fetchall(): foto = fEs.by_oldId('foto', oldId) if foto is None: continue user = Es.by_name(username) if user is None: continue if not 'tags' in foto._data: foto._data['tags'] = [] if not user._id in foto._data['tags']: foto._data['tags'].append(user._id) foto.save() print 'done'