Beispiel #1
0
    def post(self):

        sourcefile = self.request.files['myfile'][0]
        if sourcefile:
            filename = sourcefile['filename']
            if len(filename) > 0:

                unique = _get_unique_name(self.get_project_dir(),
                                          parse_archive_name(filename))

                pdb = Projects()

                project = {}
                project['id'] = pdb.predict_next_rowid()
                project['version'] = ''
                project['description'] = ''
                project['active'] = 1
                project['projectname'] = parse_archive_name(unique)
                project['projpath'] = unique

                os.mkdir(unique)

                buff = StringIO.StringIO(sourcefile['body'])

                archive = tarfile.open(fileobj=buff, mode='r:gz')
                archive.extractall(path=unique)

                vcslist = find_vcs()
                if vcslist:
                    vcs = vcslist[0](unique)
                else:
                    vcs = DumbVCS(unique)
                vcs.init_repo()

                # TODO: look for project config and retrieve project db info from it

                pdb.new(project)

                self.redirect('/projects/' + str(project['id']))

        self.redirect('')
    def post(self):

        sourcefile = self.request.files['myfile'][0]
        if sourcefile:
            filename = sourcefile['filename']
            if len(filename) > 0:

                unique = _get_unique_name(self.get_project_dir(),
                                          parse_archive_name(filename))
                
                pdb = Projects()

                project = {}
                project['id'] = pdb.predict_next_rowid()
                project['version'] = ''
                project['description'] = ''
                project['active'] = 1
                project['projectname'] = parse_archive_name(unique)
                project['projpath'] = unique

                os.mkdir(unique)
                
                buff = StringIO.StringIO(sourcefile['body'])
                
                archive = tarfile.open(fileobj=buff, mode='r:gz')
                archive.extractall(path=unique)
                
                vcslist = find_vcs()
                if vcslist:
                    vcs = vcslist[0](unique)
                else:
                    vcs = DumbVCS(unique)
                vcs.init_repo()
                
                # TODO: look for project config and retrieve project db info from it
                
                pdb.new(project)

                self.redirect('/projects/'+str(project['id']))

        self.redirect('')
    def post(self):

        if not self.request.arguments.has_key( "projectname" ):
            # First step in the import process.
            #   Just get the name, description and version of the
            #   project the user wants to import.
            #   Then pass this to the form so the user can change it.

            # Go through the process of creating a new project directory
            #   so we can read the name, description and version from the
            #   settings file.
            sourcefile = self.request.files['projectfile'][0]
            if sourcefile:
                filename = sourcefile['filename']
                if len(filename) > 0:
                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))
                    os.mkdir(unique)
                    buff = StringIO.StringIO(sourcefile['body'])
                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=unique)
                    vcslist = find_vcs()
                    if vcslist:
                        vcs = vcslist[0](unique)
                    else:
                        vcs = DumbVCS(unique)
                    vcs.init_repo()
    
                    # Update project dict with info section of config file.
                    proj = Project(unique)
                    
                    shutil.rmtree(unique)
    
                    project_info = proj.get_info()
                    self.render('projdb/import-metadata-fields.html',
                                projectname=parse_archive_name(unique),
                                description=project_info['description'],
                                version=project_info['version']
                                )
            self.redirect("/")
        else:
            forms = {}
            for field in ['projectname', 'description', 'version']:
                if field in self.request.arguments.keys():
                    forms[field] = self.request.arguments[field][0]


            sourcefile = self.request.files['projectfile'][0]
            if sourcefile:
                filename = sourcefile['filename']
                if len(filename) > 0:

                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))
                
                    pdb = Projects()

                    project = {}
                    project['id'] = pdb.predict_next_rowid()
                    project['active'] = 1
                    project['projectname'] = forms['projectname'].strip()
                    project['description'] = forms['description'].strip()
                    project['version'] = forms['version'].strip()
                    project['projpath'] = unique

                    os.mkdir(unique)
                
                    buff = StringIO.StringIO(sourcefile['body'])
                  
                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=unique)

                    vcslist = find_vcs()
                    if vcslist:
                        vcs = vcslist[0](unique)
                    else:
                        vcs = DumbVCS(unique)
                    vcs.init_repo()

                    # Update project settings.
                    proj = Project(project['projpath'])
                    dummy = proj.get_info()  # Just to get required keys.
                    info = {}
                    for key in dummy:
                        info[key] = project[key]
                    proj.set_info(info)

                    pdb.new(project)

                    self.redirect("/workspace/project?projpath=" + project['projpath'])

            self.redirect("/")
Beispiel #4
0
    def post(self):
        # The project file is uploaded once to extract the metadata.
        # It is then deleted and the metadata is used to populate another
        # import dialog, giving the user an opportunity to edit the
        # info before importing or cancel the import.
        if not 'projectname' in self.request.arguments:
            # First upload
            sourcefile = self.request.files['projectfile'][0]
            if sourcefile:
                filename = sourcefile['filename']
                if len(filename) > 0:
                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))
                    tdir = mkdtemp(prefix=unique)
                    buff = StringIO.StringIO(sourcefile['body'])
                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=tdir)
                    proj = Project(tdir)
                    project_info = proj.get_info()

                    try:
                        shutil.rmtree(tdir, onerror=onerror)
                    except:
                        pass

                    self.render('projdb/import-metadata-fields.html',
                                projectname=parse_archive_name(unique),
                                description=project_info['description'],
                                version=project_info['version'])
        else:
            # second upload
            forms = {}
            for field in ['projectname', 'description', 'version']:
                if field in self.request.arguments.keys():
                    forms[field] = self.request.arguments[field][0]

            sourcefile = self.request.files['projectfile'][0]
            if sourcefile:
                filename = sourcefile['filename']
                if len(filename) > 0:

                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))

                    pdb = Projects()

                    project = {}
                    project['id'] = pdb.predict_next_rowid()
                    project['active'] = 1
                    project['projectname'] = forms['projectname'].strip()
                    project['description'] = forms['description'].strip()
                    project['version'] = forms['version'].strip()
                    project['projpath'] = unique

                    os.mkdir(unique)

                    buff = StringIO.StringIO(sourcefile['body'])

                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=unique)

                    vcslist = find_vcs()
                    if vcslist:
                        vcs = vcslist[0](unique)
                    else:
                        vcs = DumbRepo(unique)
                    vcs.init_repo()

                    # Update project settings.
                    proj = Project(project['projpath'])
                    dummy = proj.get_info()  # Just to get required keys.
                    info = {}
                    for key in dummy:
                        info[key] = project[key]
                    proj.set_info(info)

                    pdb.new(project)

                    self.redirect("/workspace/project?projpath=" + quote_plus(project['projpath']))

        self.redirect("/")
Beispiel #5
0
    def post(self):
        # The project file is uploaded once to extract the metadata.
        # It is then deleted and the metadata is used to populate another
        # import dialog, giving the user an opportunity to edit the
        # info before importing or cancel the import.
        if not 'projectname' in self.request.arguments:
            # First upload
            sourcefile = self.request.files['projectfile'][0]
            try:
                filename = sourcefile['filename']
                if len(filename) > 0:
                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))
                    tdir = mkdtemp(prefix=unique)
                    buff = StringIO.StringIO(sourcefile['body'])
                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=tdir)
                    proj = Project(tdir)
                    project_info = proj.get_info()

                    try:
                        shutil.rmtree(tdir, onerror=onerror)
                    except:
                        pass

                    self.render('projdb/import-metadata-fields.html',
                                projectname=parse_archive_name(unique),
                                description=project_info['description'],
                                version=project_info['version'])
            except Exception as err:
                print 'ERROR: could not get metadata from', sourcefile
                exc_type, exc_value, exc_traceback = sys.exc_info()
                traceback.print_exception(exc_type, exc_value, exc_traceback)
                self.redirect('/')
        else:
            # second upload
            forms = {}
            for field in ['projectname', 'description', 'version']:
                if field in self.request.arguments.keys():
                    forms[field] = self.request.arguments[field][0]

            sourcefile = self.request.files['projectfile'][0]
            try:
                filename = sourcefile['filename']
                if len(filename) > 0:

                    unique = _get_unique_name(self.get_project_dir(),
                                              parse_archive_name(filename))

                    pdb = Projects()

                    project = {}
                    project['id'] = pdb.predict_next_rowid()
                    project['active'] = 1
                    project['projectname'] = forms['projectname'].strip()
                    project['description'] = forms['description'].strip()
                    project['version'] = forms['version'].strip()
                    project['projpath'] = unique

                    os.mkdir(unique)

                    buff = StringIO.StringIO(sourcefile['body'])

                    archive = tarfile.open(fileobj=buff, mode='r:gz')
                    archive.extractall(path=unique)

                    vcslist = find_vcs()
                    if vcslist:
                        vcs = vcslist[0](unique)
                    else:
                        vcs = DumbRepo(unique)
                    vcs.init_repo()

                    # Update project settings.
                    proj = Project(project['projpath'])
                    dummy = proj.get_info()  # Just to get required keys.
                    info = {}
                    for key in dummy:
                        info[key] = project[key]
                    proj.set_info(info)

                    pdb.new(project)

                    self.redirect("/workspace/project?projpath=" +
                                  quote_plus(project['projpath']))
            except Exception as err:
                print 'ERROR: could not get import project from', sourcefile
                exc_type, exc_value, exc_traceback = sys.exc_info()
                traceback.print_exception(exc_type, exc_value, exc_traceback)
                self.redirect('/')