Exemple #1
0
 def POST(self, hashcode):
   render = self.getRenderer().getRender()   
   db = self.getPersister().getDatabase() 
   
   form = self.getForm()
   
   
   #if not form.validates():
   #    return render.project_edit(project, form)
     
   x = web.input(upload={})
   
   
   folder = File(Path.path('projects',hashcode))
   if not folder.exists():
     os.makedirs(Path.path(folder.getPath(),folder.getName()))    
                   
   fout = open(Path.path('projects',hashcode ,x.upload.filename),'wb') # creates the file where the uploaded file should be stored
   fout.write(x.upload.file.read()) # writes the uploaded file to the newly created file.
   fout.close() # closes the file, u
   
   projectFileModel = ProjectFileModel(db)
   projectFileModel.newProjectFile(hashcode, x.upload.filename)
   
   #projectModel = ProjectModel(db)
   #project = projectModel.getProject(hashcode)
   #projectModel.updateProject(hashcode, form.d.name)
   raise web.seeother('/project_edit/'+hashcode)
Exemple #2
0
 def testFile(self):
     file = File('project.conf')
     self.assertEquals(file.isFile(), True, "is a file expected")
     self.assertEquals(file.isDirectory(), False,
                       "is not a directory expected")
     self.assertEquals(file.getName(), 'project.conf', "invalid name")
     self.assertEquals(file.getPath(), '', "invalid path")
Exemple #3
0
    def testZipPass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("current.dir", os.path.abspath('.'))
        properties.setProperty(
            "alter.dir",
            properties.getPropertyValue("current.dir") + os.sep + "alter")
        properties.setProperty(
            "create.dir",
            properties.getPropertyValue("current.dir") + os.sep + "create")

        versions = Versions()
        versionLoader = VersionLoader(versions)
        versionLoader.load(properties)
        versions.sort()
        #print versions.list()
        versionGuesser = VersionGuesser(properties, versions)
        version = versionGuesser.toFolder('1.0.0')

        currentFile = File(os.path.abspath('.'))
        current = Path.path(currentFile.getPath(), currentFile.getName())

        targetPath = Path.path(current, 'target')
        targetFile = File(targetPath)
        if not targetFile.exists():
            os.makedirs(targetPath)

        zipHandle = ZipFile(
            targetPath + os.sep + 'example_' + version + '.zip', 'w')

        excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS')

        files = Files.list(currentFile, True)

        filters = Filters()

        excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS')
        for excludedFolder in excludedFolders:
            ef = File(excludedFolder)
            ff = FileFolderFilter(ef)
            filters.add(ff)

        for file in files:

            result = False
            for excludedFolder in excludedFolders:
                if excludedFolder in file.getPath() + file.getName():
                    result = True
                    break

            #if filters.accept(file)==False:
            if not result:
                source = Path.path(file.getPath(), file.getName())
                target = source.replace(current, '')
                print file.getPath(), file.getName()

                zipHandle.write(source, target, zipfile.ZIP_DEFLATED)