Exemple #1
0
 def mkDefThumb(self):
     info = mkImageWithFrame(self.max_thumb_width, self.max_thumb_height)
     if not info.is_image():
         return False
     fp = FileProcess()
     image_info = fp.copyImage(info.file_path, short_dir = self.base_dir)
     if not image_info or not image_info.is_image():
         return False
     self.def_thumb_path = image_info.short_path
     return True
Exemple #2
0
 def mkDefThumb(self):
     info = mkImageWithFrame(self.max_thumb_width, self.max_thumb_height)
     if not info.is_image():
         return False
     fp = FileProcess()
     image_info = fp.copyImage(info.file_path, short_dir=self.base_dir)
     if not image_info or not image_info.is_image():
         return False
     self.def_thumb_path = image_info.short_path
     return True
 def testFileCopy(self):
     write_str = 'Temp file'
     source_file = mkTempFile(write_str)
     fp = FileProcess()
     target_file = fp.copyFile(source_file, ext='.txt')
     full_target_path = fp.fullPath(target_file)
     s = getFileContent(full_target_path)
     self.assertEquals(s, write_str)
     (_, ext) = os.path.splitext(target_file)
     self.assertEquals(ext, '.txt')
     os.unlink(source_file)
 def testFileCopy(self):
     write_str = 'Temp file'
     source_file = mkTempFile(write_str)
     fp = FileProcess()
     target_file = fp.copyFile(source_file, ext='.txt')
     full_target_path = fp.fullPath(target_file)
     s = getFileContent(full_target_path)
     self.assertEquals(s, write_str)
     (_, ext) = os.path.splitext(target_file)
     self.assertEquals(ext, '.txt')
     os.unlink(source_file)
 def testImageCopy(self):
     it = ImageTransform.create(ImageTransform.STD, 100, 100);
     fp = FileProcess()
     info = fp.copyImage(fileInTestDir('img/test.jpg'), transform = it, short_dir = 'i') 
     self.assertEquals(info.is_image(), True)
     self.assertEquals(info.content_type, ImageInfo.JPEG)
     self.assert_(info.width <= 100)
     self.assert_(info.height <= 100) 
     split_p = info.short_path.split(os.path.sep)
     self.assert_('i' in split_p)
     self.assert_('img' in split_p)
     info = fp.copyImage(fileInTestDir('img/test.jpg')) 
     self.assertEquals(info.is_image(), True)
     self.assertEquals(info.content_type, ImageInfo.JPEG)
     self.assertEquals(info.width, 418)
     self.assertEquals(info.height, 604) 
Exemple #6
0
 def uploadFromFile(self, source_file):
     image_type = self.image_type
     fp = FileProcess()
     thumb_info = fp.copyImage(source_file, transform = image_type.thumb_transform_image,\
             short_dir = image_type.base_dir)
     if not thumb_info or not thumb_info.is_image():
         return False
     image_info = fp.copyImage(source_file, short_dir = image_type.base_dir)
     if not image_info or not image_info.is_image():
         return False
     self.thumb_path = thumb_info.short_path
     self.thumb_width = thumb_info.width
     self.thumb_height = thumb_info.height
     self.image_path = image_info.short_path
     self.image_width = image_info.width
     self.image_height = image_info.height
     self.content_type = image_info.content_type
     return True
 def testImageCopy(self):
     it = ImageTransform.create(ImageTransform.STD, 100, 100)
     fp = FileProcess()
     info = fp.copyImage(fileInTestDir('img/test.jpg'),
                         transform=it,
                         short_dir='i')
     self.assertEquals(info.is_image(), True)
     self.assertEquals(info.content_type, ImageInfo.JPEG)
     self.assert_(info.width <= 100)
     self.assert_(info.height <= 100)
     split_p = info.short_path.split(os.path.sep)
     self.assert_('i' in split_p)
     self.assert_('img' in split_p)
     info = fp.copyImage(fileInTestDir('img/test.jpg'))
     self.assertEquals(info.is_image(), True)
     self.assertEquals(info.content_type, ImageInfo.JPEG)
     self.assertEquals(info.width, 418)
     self.assertEquals(info.height, 604)
    def testDefThumb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 345
        it.max_thumb_width = 234
        session.add(it)
        session.commit()
        ret = it.mkDefThumb()
        self.assertEquals(ret, True)
        self.assert_(it.def_thumb_path)
        fp = FileProcess()
        self.assertNotEquals(it.def_thumb_path[0], '/')
        info = ImageInfo(fp.fullPath(it.def_thumb_path))
        self.assertEquals(info.is_image(), True)
        self.assertEquals(info.height, 345)
        self.assertEquals(info.width, 234)

        session.delete(it)
        session.commit()
    def testDefThumb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 345
        it.max_thumb_width = 234
        session.add(it)
        session.commit()
        ret = it.mkDefThumb()
        self.assertEquals(ret, True)
        self.assert_(it.def_thumb_path)
        fp = FileProcess()
        self.assertNotEquals(it.def_thumb_path[0], '/')
        info = ImageInfo(fp.fullPath(it.def_thumb_path))
        self.assertEquals(info.is_image(), True)
        self.assertEquals(info.height, 345)
        self.assertEquals(info.width, 234)

        session.delete(it)
        session.commit()
Exemple #10
0
 def uploadFromFile(self, source_file):
     image_type = self.image_type
     fp = FileProcess()
     thumb_info = fp.copyImage(source_file, transform = image_type.thumb_transform_image,\
             short_dir = image_type.base_dir)
     if not thumb_info or not thumb_info.is_image():
         return False
     image_info = fp.copyImage(source_file, short_dir=image_type.base_dir)
     if not image_info or not image_info.is_image():
         return False
     self.thumb_path = thumb_info.short_path
     self.thumb_width = thumb_info.width
     self.thumb_height = thumb_info.height
     self.image_path = image_info.short_path
     self.image_width = image_info.width
     self.image_height = image_info.height
     self.content_type = image_info.content_type
     return True
    def testAddImageToDb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 50
        it.max_thumb_width = 150
        it.base_dir = 'b/a'
        it.transform_type = ImageTransform.STD
        session.add(it)
        img = Image(it)
        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        session.add(img)
        session.commit()
        old_thumb_path = img.thumb_path
        old_image_path = img.image_path
        self.assert_(os.path.isfile(FileProcess.fullPath(img.thumb_path)))
        self.assert_(os.path.isfile(FileProcess.fullPath(img.image_path)))
        split_p = img.thumb_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        split_p = img.image_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        self.assert_(img.thumb_width <= 150)
        self.assert_(img.thumb_height <= 50)
        self.assertEquals(img.content_type, ImageInfo.JPEG)
        self.assertEquals(img.image_width, 418)
        self.assertEquals(img.image_height, 604)

        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_thumb_path)))
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_image_path)))

        session.delete(img)
        session.delete(it)
        session.commit()
    def testAddImageToDb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 50
        it.max_thumb_width = 150
        it.base_dir = 'b/a'
        it.transform_type = ImageTransform.STD
        session.add(it)
        img = Image(it)
        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        session.add(img)
        session.commit()
        old_thumb_path = img.thumb_path
        old_image_path = img.image_path
        self.assert_(os.path.isfile(FileProcess.fullPath(img.thumb_path)))
        self.assert_(os.path.isfile(FileProcess.fullPath(img.image_path)))
        split_p = img.thumb_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        split_p = img.image_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        self.assert_(img.thumb_width <= 150)
        self.assert_(img.thumb_height <= 50) 
        self.assertEquals(img.content_type, ImageInfo.JPEG)
        self.assertEquals(img.image_width, 418)
        self.assertEquals(img.image_height, 604) 

        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_thumb_path)))
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_image_path)))

        session.delete(img)
        session.delete(it)
        session.commit()
Exemple #13
0
 def set_event_listner(target, value, oldvalue, initiator):
     if oldvalue:
         full_path = FileProcess.fullPath(oldvalue)
         if (os.path.isfile(full_path)):
             os.unlink(full_path)
Exemple #14
0
 def set_event_listner(target, value, oldvalue, initiator):
     if oldvalue:
         full_path = FileProcess.fullPath(oldvalue)
         if (os.path.isfile(full_path)):
             os.unlink(full_path)