Esempio n. 1
0
def migrate_old_storage(context):
    catalog = getToolByName(context, 'portal_catalog')
    portal = getSite()
    gsettings = GlobalSettings(portal)
    for brain in catalog(object_provides=IFileContent.__identifier__):
        file = brain.getObject()
        if file.getLayout() == 'documentviewer':
            settings = Settings(file)
            if settings.storage_version == 1:
                if settings.storage_type == 'File':
                    current_location = storage.getResourceDirectory(
                        gsettings=gsettings, settings=settings)
                    if not exists(current_location):
                        raise Exception(
                            "oops, can't find storage location %s" %
                            (current_location))
                    settings.storage_version = STORAGE_VERSION
                    new_location = storage.getResourceDirectory(
                        gsettings=gsettings, settings=settings)
                    # only make base
                    mkdir_p(
                        os.path.sep.join(new_location.split(os.path.sep)[:-1]))
                    shutil.move(current_location, new_location)
                    # need to commit these eagerly since a failed
                    # migration could leave some migrated wrong
                    transaction.commit()
                else:
                    settings.storage_version = STORAGE_VERSION
Esempio n. 2
0
def migrate_old_storage(context):
    catalog = getToolByName(context, 'portal_catalog')
    portal = getSite()
    gsettings = GlobalSettings(portal)
    for brain in catalog(object_provides=IFileContent.__identifier__):
        file = brain.getObject()
        if file.getLayout() == 'documentviewer':
            settings = Settings(file)
            if settings.storage_version == 1:
                if settings.storage_type == 'File':
                    current_location = storage.getResourceDirectory(
                        gsettings=gsettings, settings=settings)
                    if not exists(current_location):
                        raise Exception(
                            "oops, can't find storage location %s" % (
                                current_location))
                    settings.storage_version = STORAGE_VERSION
                    new_location = storage.getResourceDirectory(
                        gsettings=gsettings, settings=settings)
                    # only make base
                    mkdir_p(os.path.sep.join(
                        new_location.split(os.path.sep)[:-1]))
                    shutil.move(current_location, new_location)
                    # need to commit these eagerly since a failed
                    # migration could leave some migrated wrong
                    transaction.commit()
                else:
                    settings.storage_version = STORAGE_VERSION
Esempio n. 3
0
 def get_storage_dir(self):
     if self.gsettings.storage_type == 'Blob':
         storage_dir = tempfile.mkdtemp()
     else:
         storage_dir = storage.getResourceDirectory(
             gsettings=self.gsettings, settings=self.settings)
         if not os.path.exists(storage_dir):
             mkdir_p(storage_dir)
     return storage_dir
    def get_storage_dir(self):
        if self.gsettings.storage_type == 'Blob':
            storage_dir = tempfile.mkdtemp()
        else:
            storage_dir = storage.getResourceDirectory(gsettings=self.gsettings,
                                                       settings=self.settings)
            if not os.path.exists(storage_dir):
                mkdir_p(storage_dir)

        return storage_dir
    def handleFileObfuscation(self):
        """
        This is in case you have serve file storage outside
        of the plone server and you have no way of doing
        permission checks. This will only work if editors
        are on the same server as the files getting stored.
        DV's file storage traverser is the only resolver
        that will know how to handle the secret location.

        Publishing content is the only way to get it out
        of this secret location.
        """
        settings = self.settings
        if not settings.obfuscate_secret:
            settings.obfuscate_secret = str(random.randint(1, 9999999999))

        storage_dir = self.storage_dir
        secret_dir = os.path.join(storage_dir,
                                  settings.obfuscate_secret)
        if self.gsettings.storage_obfuscate is True and \
                settings.storage_type == 'File' and not self.anonCanView():
            # alright, we know we should be obfuscating the path now.
            # conversions are always done on the same path structure
            # so we just move that path structure into the secret folder
            settings.obfuscated_filepath = True
            if os.path.exists(secret_dir):
                # already exists
                if len(os.listdir(secret_dir)) > 0 and \
                        len(os.listdir(storage_dir)) == 1:
                    return
            else:
                mkdir_p(secret_dir)

            for folder in os.listdir(storage_dir):
                path = os.path.join(storage_dir, folder)
                if not os.path.isdir(path) or \
                        folder == settings.obfuscate_secret:
                    continue

                newpath = os.path.join(secret_dir, folder)
                shutil.move(path, newpath)
        else:
            settings.obfuscated_filepath = False
            if os.path.exists(secret_dir):
                shutil.rmtree(secret_dir)
Esempio n. 6
0
def get_file_locations(filename, content_type, gsettings):
    storage_dir = path.join(gsettings.storage_location, filename)
    if content_type == 'application/octetstream':
        filename_dump = path.join(
            gsettings.storage_location, '.'.join((filename, 'html')))
    else:
        filename_dump = path.join(
            gsettings.storage_location, filename)
        if filename_dump.endswith(filename):
            filename_dump = '.'.join([filename_dump, 'dat'])
    filename_pdf = path.join(storage_dir, 'converted.pdf')

    if not path.exists(storage_dir):
        mkdir_p(storage_dir)
    if path.exists(filename_dump):
        remove(filename_dump)

    return (storage_dir, filename_dump, filename_pdf)
Esempio n. 7
0
    def handleFileObfuscation(self):
        """
        This is in case you have serve file storage outside
        of the plone server and you have no way of doing
        permission checks. This will only work if editors
        are on the same server as the files getting stored.
        DV's file storage traverser is the only resolver
        that will know how to handle the secret location.

        Publishing content is the only way to get it out
        of this secret location.
        """
        settings = self.settings
        if not settings.obfuscate_secret:
            settings.obfuscate_secret = str(random.randint(1, 9999999999))

        storage_dir = self.storage_dir
        secret_dir = os.path.join(storage_dir, settings.obfuscate_secret)
        if self.gsettings.storage_obfuscate is True and \
                settings.storage_type == 'File' and not self.anonCanView():
            # alright, we know we should be obfuscating the path now.
            # conversions are always done on the same path structure
            # so we just move that path structure into the secret folder
            settings.obfuscated_filepath = True
            if os.path.exists(secret_dir):
                # already exists
                if len(os.listdir(secret_dir)) > 0 and \
                        len(os.listdir(storage_dir)) == 1:
                    return
            else:
                mkdir_p(secret_dir)

            for folder in os.listdir(storage_dir):
                path = os.path.join(storage_dir, folder)
                if not os.path.isdir(path) or \
                        folder == settings.obfuscate_secret:
                    continue

                newpath = os.path.join(secret_dir, folder)
                shutil.move(path, newpath)
        else:
            settings.obfuscated_filepath = False
            if os.path.exists(secret_dir):
                shutil.rmtree(secret_dir)