Пример #1
0
 def testCreateAndDelete(self):
     """
     Test we have a resource directory and resource files can be stored in
     """
     oliver = Resource(self.package, Path("oliver.jpg"))
     self.assert_((self.package.resourceDir/"oliver.jpg").exists())
     oliver.delete()
     self.assert_(not (self.package.resourceDir/"oliver.jpg").exists())
Пример #2
0
 def testCreateAndDelete(self):
     """
     Test we have a resource directory and resource files can be stored in
     """
     myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon", self.package.root)
     oliver = Resource(myIdevice, Path("oliver.jpg"))
     self.assert_((self.package.resourceDir/"oliver.jpg").exists())
     oliver.delete()
     self.assert_(not (self.package.resourceDir/"oliver.jpg").exists())
Пример #3
0
 def testCreateAndDelete(self):
     """
     Test we have a resource directory and resource files can be stored in
     """
     myIdevice = Idevice("My Idevice", "UoA", "Testing", "Help tip", "icon",
                         self.package.root)
     oliver = Resource(myIdevice, Path("oliver.jpg"))
     self.assert_((self.package.resourceDir / "oliver.jpg").exists())
     oliver.delete()
     self.assert_(not (self.package.resourceDir / "oliver.jpg").exists())
Пример #4
0
class FileField(Field):
    """
    Field for storing an individual file
    """
    persistenceVersion = 5
    """
    alwaysNameTo - make sure that this file always a certain final name
    """
    def __init__(self,
                 idevice,
                 alwaysNameTo=None,
                 desc="File Field",
                 help="File Field Help"):
        Field.__init__(self, desc, help)
        self.idevice = idevice
        self.fileResource = None
        self.fileInstruc = "Upload a file"
        self.alwaysNameTo = alwaysNameTo
        self.fileDescription = TextField("Description")
        self.fileDescription.idevice = self

    def uploadFile(self, filePath):
        if self.fileResource is not None:
            self.fileResource.delete()

        finalName = str(filePath)
        if self.alwaysNameTo is not None:
            from os.path import dirname
            from shutil import copyfile
            dirName = dirname(filePath)
            finalName = dirName + "/" + self.alwaysNameTo
            copyfile(filePath, finalName)

        if self.fileDescription.content == "":
            self.fileDescription.content = os.path.basename(filePath)

        resourceFile = Path(finalName)
        if resourceFile.isfile():
            self.idevice.message = ""
            self.fileResource = Resource(self.idevice, resourceFile)

    def deleteFile(self):
        if self.fileResource is not None:
            self.fileResource.delete()
            self.fileResource = None

    def upgradeToVersion4(self):
        self.fileDescription = TextField("Description")

    def upgradeToVersion5(self):
        self.fileDescription.idevice = self
Пример #5
0
class FileField(Field):
    """
    Field for storing an individual file
    """
    persistenceVersion = 5
    
    """
    alwaysNameTo - make sure that this file always a certain final name
    """
    def __init__(self, idevice, alwaysNameTo=None, desc="File Field", help="File Field Help"):
        Field.__init__(self, desc, help)
        self.idevice = idevice
        self.fileResource = None
        self.fileInstruc = "Upload a file"
        self.alwaysNameTo = alwaysNameTo
        self.fileDescription = TextField("Description")
        self.fileDescription.idevice = self
        
    def uploadFile(self, filePath):
        if self.fileResource is not None:
            self.fileResource.delete()
            
        finalName = str(filePath)
        if self.alwaysNameTo is not None:
            from os.path import dirname
            from shutil import copyfile
            dirName = dirname(filePath)
            finalName = dirName + "/" + self.alwaysNameTo
            copyfile(filePath, finalName)
        
        if self.fileDescription.content == "":
            self.fileDescription.content = os.path.basename(filePath)
            
        resourceFile = Path(finalName)
        if resourceFile.isfile():
            self.idevice.message = ""
            self.fileResource = Resource(self.idevice, resourceFile)
    
    def deleteFile(self):
        if self.fileResource is not None:
            self.fileResource.delete()
            self.fileResource = None
    
    def upgradeToVersion4(self):
        self.fileDescription = TextField("Description")

    def upgradeToVersion5(self):
        self.fileDescription.idevice = self
Пример #6
0
class FileField(Field):
    """
    Field for storing an individual file
    """
    persistenceVersion = 5
    """
    alwaysNameTo - make sure that this file always a certain final name
    """
    def __init__(self,
                 idevice,
                 alwaysNameTo=None,
                 desc="File Field",
                 help="File Field Help"):
        Field.__init__(self, desc, help)
        self.idevice = idevice
        self.fileResource = None
        self.fileInstruc = "Upload a file"
        self.alwaysNameTo = alwaysNameTo
        self.fileDescription = TextField("Description")
        self.fileDescription.idevice = self

    def uploadFile(self, filePath):
        if self.fileResource is not None:
            self.fileResource.delete()

        finalName = str(filePath)
        if self.alwaysNameTo is not None:
            from os.path import dirname
            from shutil import copyfile
            dirName = dirname(filePath)
            finalName = dirName + "/" + self.alwaysNameTo
            copyfile(filePath, finalName)

        if self.fileDescription.content == "":
            self.fileDescription.content = os.path.basename(filePath)

        resourceFile = Path(finalName)
        if resourceFile.isfile():
            self.idevice.message = ""
            self.fileResource = Resource(self.idevice, resourceFile)

    def deleteFile(self):
        if self.fileResource is not None:
            self.fileResource.delete()
            self.fileResource = None

    def get_translatable_properties(self):
        """
        Get a list of translatable property names that can be translated.

        :rtype: list
        :return: List of translatable properties of the field.
        """
        # The only translatable fields in this Idevice is the description (which
        # is a field in itself)
        return self.fileDescription.get_translatable_properties()

    def translate(self):
        """
        Do the actual translation.
        """
        # We only have a translatable property, as it is also a field, just call
        # translate() on it
        self.fileDescription.translate()

    def upgradeToVersion4(self):
        self.fileDescription = TextField("Description")

    def upgradeToVersion5(self):
        self.fileDescription.idevice = self
Пример #7
0
class FileField(Field):
    """
    Field for storing an individual file
    """
    persistenceVersion = 5
    
    """
    alwaysNameTo - make sure that this file always a certain final name
    """
    def __init__(self, idevice, alwaysNameTo=None, desc="File Field", help="File Field Help"):
        Field.__init__(self, desc, help)
        self.idevice = idevice
        self.fileResource = None
        self.fileInstruc = "Upload a file"
        self.alwaysNameTo = alwaysNameTo
        self.fileDescription = TextField("Description")
        self.fileDescription.idevice = self
        
    def uploadFile(self, filePath):
        if self.fileResource is not None:
            self.fileResource.delete()
            
        finalName = str(filePath)
        if self.alwaysNameTo is not None:
            from os.path import dirname
            from shutil import copyfile
            dirName = dirname(filePath)
            finalName = dirName + "/" + self.alwaysNameTo
            copyfile(filePath, finalName)
        
        if self.fileDescription.content == "":
            self.fileDescription.content = os.path.basename(filePath)
            
        resourceFile = Path(finalName)
        if resourceFile.isfile():
            self.idevice.message = ""
            self.fileResource = Resource(self.idevice, resourceFile)
    
    def deleteFile(self):
        if self.fileResource is not None:
            self.fileResource.delete()
            self.fileResource = None

    def get_translatable_properties(self):
        """
        Get a list of translatable property names that can be translated.

        :rtype: list
        :return: List of translatable properties of the field.
        """
        # The only translatable fields in this Idevice is the description (which
        # is a field in itself)
        return self.fileDescription.get_translatable_properties()

    def translate(self):
        """
        Do the actual translation.
        """
        # We only have a translatable property, as it is also a field, just call
        # translate() on it
        self.fileDescription.translate()

    def upgradeToVersion4(self):
        self.fileDescription = TextField("Description")

    def upgradeToVersion5(self):
        self.fileDescription.idevice = self