Exemplo n.º 1
0
    def updateBundleItem(self, item, namespace = None, **attrs):
        """
        Actualiza un bundle item
        """
        if len(attrs) == 1 and "name" in attrs and attrs["name"] == item.name:
            #Updates que no son updates
            return item

        self.updateBundleItemCacheCoherence(item, attrs)
         
        #TODO: Este paso es importante para obtener el namespace, quiza ponerlo en un metodo para trabajarlo un poco más
        namespace = namespace or self.defaultNamespace
        
        if item.bundle.isProtected and not item.bundle.isSafe:
            self.updateBundle(item.bundle, namespace)

        if item.isProtected and not item.isSafe:
            #Safe Bundle Item
            path = os.path.join(item.bundle.path(namespace), item.FOLDER, os.path.basename(item.path(self.protectedNamespace)))
            item.addSource(namespace, path)
            self.logger.debug("Add namespace '%s' in source %s for bundle item." % (namespace, path))
        elif not item.isProtected and "name" in attrs:
            #Move Bundle Item
            namePattern = "%%s.%s" % item.EXTENSION if item.EXTENSION else "%s"
            path = ensurePath(os.path.join(item.bundle.path(namespace), item.FOLDER, namePattern), self.convertToValidPath(attrs["name"]))
            item.relocateSource(namespace, path)
        item.update(attrs)
        item.save(namespace)
        item.updateMtime(namespace)
        self.modifyBundleItem(item)
        return item
Exemplo n.º 2
0
 def updateTemplateFile(self, templateFile, namespace = None, **attrs):
     namespace = namespace or self.defaultNamespace
     template = templateFile.template
     if template.isProtected and not template.isSafe:
         self.updateBundleItem(template, namespace)
     if "name" in attrs:
         path = ensurePath(os.path.join(template.path(namespace), "%s"), self.convertToValidPath(attrs["name"]))
         templateFile.relocate(path)
     templateFile.update(attrs)
     self.modifyBundleItem(templateFile)
     return templateFile
Exemplo n.º 3
0
 def createTemplateFile(self, name, template, namespace = None):
     namespace = namespace or self.defaultNamespace
     if template.isProtected and not template.isSafe:
         self.updateBundleItem(template, namespace)
     path = ensurePath(os.path.join(template.path(namespace), "%s"), self.convertToValidPath(name))
     file = PMXTemplateFile(path, template)
     #No es la mejor forma pero es la forma de guardar el archivo
     file = self.addTemplateFile(file)
     template.files.append(file)
     file.save()
     return file
Exemplo n.º 4
0
 def updateTheme(self, theme, namespace = None, **attrs):
     """
     Actualiza un themes
     """
     namespace = namespace or self.defaultNamespace
     if theme.isProtected and not theme.isSafe:
         path = os.path.join(self.namespaces[namespace]['Themes'], os.path.basename(theme.path(self.protectedNamespace)))
         theme.addSource(namespace, path)
     elif not theme.isProtected and "name" in attrs:
         path = ensurePath(os.path.join(os.path.dirname(theme.path(namespace)), "%s.tmTheme"), self.convertToValidPath(attrs["name"]))
         theme.relocateSource(namespace, path)
     theme.update(attrs)
     theme.save(namespace)
     theme.updateMtime(namespace)
     self.modifyTheme(theme)
     return theme
Exemplo n.º 5
0
 def createBundle(self, name, namespace = None):
     """
     Crea un bundle nuevo lo agrega en los bundles y lo retorna,
     Precondiciones:
         Tenes por lo menos dos espacios de nombre el base o proteguido y uno donde generar los nuevos bundles
         El nombre tipo Title.
         El nombre no este entre los nombres ya cargados.
     Toma el ultimo espacio de nombres creado como espacio de nombre por defecto para el bundle nuevo.
     """
     namespace = namespace or self.defaultNamespace
     basePath = self.basePath("Bundles", namespace)
     path = ensurePath(os.path.join(basePath, "%s.tmbundle"), self.convertToValidPath(name))
     bundle = PMXBundle(self.uuidgen(), { 'name': name })
     bundle.setManager(self)
     bundle.addSource(namespace, path)
     bundle = self.addBundle(bundle)
     self.addManagedObject(bundle)
     return bundle
Exemplo n.º 6
0
    def updateBundle(self, bundle, namespace = None, **attrs):
        """Actualiza un bundle"""
        if len(attrs) == 1 and "name" in attrs and attrs["name"] == bundle.name:
            #Updates que no son updates
            return bundle

        namespace = namespace or self.defaultNamespace
        
        if bundle.isProtected and not bundle.isSafe:
            #Safe bundle
            basePath = self.basePath("Bundles", namespace)
            path = os.path.join(basePath, os.path.basename(bundle.path(self.protectedNamespace)))
            bundle.addSource(namespace, path)
            self.logger.debug("Add namespace '%s' in source %s for bundle." % (namespace, path))
        elif not bundle.isProtected and "name" in attrs:
            #Move bundle
            path = ensurePath(os.path.join(os.path.dirname(bundle.path(namespace)), "%s.tmbundle"), self.convertToValidPath(attrs["name"]))
            bundle.relocateSource(namespace, path)
        bundle.update(attrs)
        bundle.save(namespace)
        bundle.updateMtime(namespace)
        self.modifyBundle(bundle)
        return bundle