Exemple #1
0
def upload_entity_thumbnail(entity):
    """
    Upload thumbnail file for given entity to object storage.
    """
    preview_folder = os.getenv("PREVIEW_FOLDER", "/opt/zou/previews")
    local = LocalBackend("local",
                         {"root": os.path.join(preview_folder, "pictures")})

    file_path = local.path("thumbnails-" + str(entity.id))
    if entity.has_avatar:
        file_store.add_picture("thumbnails", str(entity.id), file_path)
        print("%s uploaded" % file_path)
Exemple #2
0
def download_entity_thumbnail(entity):
    """
    Download thumbnail file for given entity from object storage and store it
    locally.
    """
    local = LocalBackend("local",
                         {"root": os.path.join(preview_folder, "pictures")})

    file_path = local.path("thumbnails-" + str(entity.id))
    dirname = os.path.dirname(file_path)
    if entity.has_avatar:
        if not os.path.exists(dirname):
            os.makedirs(dirname)
        with open(file_path, "wb") as tmp_file:
            for chunk in file_store.open_picture("thumbnails", str(entity.id)):
                tmp_file.write(chunk)
 def setUp(self):
     super(LocalBackendTest, self).setUp()
     self.test_dir = tempfile.mkdtemp()
     self.config = Config({
         'root': self.test_dir,
     })
     self.backend = LocalBackend('test', self.config)
Exemple #4
0
def upload_preview(preview_file):
    """
    Upload all files link to preview file entry: orginal file and variants.
    """
    print("upload preview %s (%s)" % (preview_file.id, preview_file.extension))

    preview_folder = os.getenv("PREVIEW_FOLDER", "/opt/zou/previews")
    local_picture = LocalBackend(
        "local", {"root": os.path.join(preview_folder, "pictures")})
    local_movie = LocalBackend(
        "local", {"root": os.path.join(preview_folder, "movies")})
    local_file = LocalBackend("local",
                              {"root": os.path.join(preview_folder, "files")})

    is_movie = preview_file.extension == "mp4"
    is_picture = preview_file.extension == "png"
    is_file = not is_movie and not is_picture

    preview_file_id = str(preview_file.id)
    file_key = "previews-%s" % preview_file_id
    if is_picture:
        file_path = local_picture.path(file_key)
        ul_func = file_store.add_picture
        exists_func = file_store.exists_picture
    elif is_movie:
        file_path = local_movie.path(file_key)
        ul_func = file_store.add_movie
        exists_func = file_store.exists_movie
    elif is_file:
        file_path = local_file.path(file_key)
        ul_func = file_store.add_file
        exists_func = file_store.exists_file

    if is_movie or is_picture:
        for prefix in ["thumbnails", "thumbnails-square", "original"]:
            pic_file_path = local_picture.path("%s-%s" %
                                               (prefix, str(preview_file.id)))
            if os.path.exists(pic_file_path) and not file_store.exists_picture(
                    prefix, preview_file_id):
                file_store.add_picture(prefix, preview_file_id, pic_file_path)

    prefix = "previews"
    if os.path.exists(file_path) and not exists_func(prefix, preview_file_id):
        ul_func(prefix, preview_file_id, file_path)
    print("%s uploaded" % file_path)
Exemple #5
0
from zou.app.models.time_spent import TimeSpent

from zou.app.services import deletion_service, tasks_service
from zou.app.stores import file_store
from flask_fs.backends.local import LocalBackend
from zou.app.utils import events

logger = logging.getLogger()
logger.setLevel(logging.INFO)
console_handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)

preview_folder = os.getenv("PREVIEW_FOLDER", "/opt/zou/previews")
local_picture = LocalBackend(
    "local", {"root": os.path.join(preview_folder, "pictures")})
local_movie = LocalBackend("local",
                           {"root": os.path.join(preview_folder, "movies")})
local_file = LocalBackend("local",
                          {"root": os.path.join(preview_folder, "files")})

event_name_model_map = {
    "asset": Entity,
    "asset-type": EntityType,
    "build-job": BuildJob,
    "custom-action": CustomAction,
    "comment": Comment,
    "department": Department,
    "entity": Entity,
    "entity-link": EntityLink,
    "entity-type": EntityType,
 def test_default_root(self):
     self.app.config['FS_ROOT'] = self.test_dir
     root = self.filename('default')
     backend = LocalBackend('default', Config({}))
     with self.app.app_context():
         self.assertEqual(backend.root, root)
 def test_backend_root(self, app):
     app.config['FS_LOCAL_ROOT'] = str(self.test_dir)
     root = self.test_dir.join('default')
     backend = LocalBackend('default', Config({}))
     assert backend.root == root
 def setup(self, tmpdir):
     self.test_dir = tmpdir
     self.config = Config({
         'root': str(tmpdir),
     })
     self.backend = LocalBackend('test', self.config)