Ejemplo n.º 1
0
    def add(self):
        """Create the missing elements and upload the files to the server.

        Use the check method to get the different elements exist on the server.
        Create the missing element and upload the files on the server.
        The files are listed in the path directory which is specify with the option ("-d", "--dir")


        >>> python gforge_upload -d /home/user add openalea:VPlants:0.8:*.egg
              Upload the files which exists in /home/user directory to /VPlants package
                                                                     /release 0.8
                                                                     /openalea project
                                                                     /on the gforge server
        """
        print green('Checking and connecting to the forge. Be patient')
        self.check_project()
        self.check_packages()
        self.check_releases()
        self.check_files()

        files = glob.glob(self.glob)
        if len(files)==0:
            print 'No file with glob %s found. Nothing to upload' % (self.glob)
            sys.exit(0)

        print purple('You are about to upload the following files on the gforge (in %s): ' % self.get_location())
        for f in files:	
            print '\t%s' %f

        for file in files:
            if os.path.basename(file) in self.server_files:
                print purple('%s already present on the gforge (in %s). It will therefore be replaced' %(os.path.basename(file), self.get_location()))
                if self.remove_file(file):
                    self.add_file(file)
            else:
                self.add_file(file)
Ejemplo n.º 2
0
    def remove(self):
        """Remove the elements (package/release/and files) on the server.

        Use the check method to get the different elements exist on the server.
        Remove the element listed on the server.

        >>> python gforge_upload remove openalea:VPlants:0.8:*.egg
            Remove all the '.egg' files of /VPlants package
                                           /release 0.8
                                           /openalea project
                                           /on the gforge server

        """
        print 'Checking and connecting to the forge. Be patient'
        self.check_project()
        self.check_packages()
        # if only --package is provided, we assume that the whole package must be deleted included all the files
        # if the --package and --release are provided, we assume that the release of this package must be deleted included the files
        # if the --package and --release and --glob are provided, we assume that files of project/package/release must be deleted
        if self.package and self.glob and self.release:
            self.check_releases()
            files = server.get_files(self.project, self.package, self.release)
            if len(files)==0:
                print 'No file with glob % found. Nothing to upload' % (self.glob)
                sys.exit(0)
            for file in files:
                if fnmatch(file, self.glob):
                    self.remove_file(file)
                else:
                    print '%s does not match the glob option %s. Skipped' % (file, self.glob)


        elif self.package and self.release and not self.glob:
            self.check_releases()
            files = server.get_files(self.project, self.package, self.release)
            print purple('You are about to delete the release %s that contains the following files: ' % self.get_location())
            for f in files:	
                print '\t%s' %f
            if self.ask(purple('Shall we proceed ?')):
                if self.dry_run:
                    pass
                else:
                    self.server.remove_release(self.project, self.package, self.release)
                print 'Release %s deleted' % self.release
            else:
                print 'skipped'

        elif self.package and not self.release and not self.glob:
            releases = server.get_releases(self.project, self.package)
            if len(releases)==0:
                if self.ask(purple('Shall we proceed in deleting empty package %s?' % self.package)):
                    if self.dry_run:
                        pass
                    else:
                        self.server.remove_package(self.project, self.package)
                else:
                    print 'skipped'

            for release in releases:
                files = server.get_files(self.project, self.package, release)
                print purple('You are about to delete the release %s that contains the following files: ' % release)
                for f in files:	
                    print '\t%s' %f

            if self.ask(purple('Shall we proceed ?')):
                if self.dry_run:
                    pass
                else:
                    self.server.remove_package(self.project, self.package)
                    print green('done')
            else:
                print 'skipped'
Ejemplo n.º 3
0
    def run(self, color=True):
        """Enter in all package defined and Executing 'python setup.py' with
           user command.

        """
        import sys
        import os
        if color:
            try:
                from openalea.deploy.console import bold, red, green, \
                    color_terminal, nocolor, underline, purple
            except:
                try:
                    sys.path.insert(
                        0, os.path.join('deploy', 'src', 'openalea', 'deploy'))
                    from console import bold, red, green, \
                        color_terminal, nocolor, underline, purple
                except:
                    pass
            if not color_terminal():
                # Windows' poor cmd box doesn't understand ANSI sequences
                nocolor()
        else:
            bold = purple = red = green = underline = str

        print bold("Running multisetup version %s" % __revision__.split()[2])

        project_dir = self.curdir.basename()
        directories = [
            self.curdir.joinpath(package) for package in self.packages
        ]

        print 'Will process the following directories: ',
        for directory in directories:
            print bold(directory.basename()),
        print ''

        try:
            for directory in directories:
                try:
                    os.chdir(directory)
                    print underline('Entering %s package' %
                                    directory.basename())
                except OSError, e:
                    print underline('Entering %s package' %
                                    directory.basename()),
                    print red("cannot find this directory (%s)" %
                              directory.basename())
                    print e

                print 'Python exec : ', sys.executable

                #print underline('Entering %s package' % directory.basename())
                for cmd in self.commands:
                    setup_command = '%s setup.py %s ' % (sys.executable, cmd)
                    print "\tExecuting " + setup_command + '...processing',

                    #Run setup.py with user commands
                    outputs = None
                    errors = None
                    if self.verbose:
                        process = Popen(setup_command, shell=True)
                        status = process.wait()
                    else:
                        process = Popen(setup_command,
                                        stdout=PIPE,
                                        stderr=PIPE,
                                        shell=True)
                        #status = process.wait()
                        outputs, errors = process.communicate()
                    if process.returncode == 0:
                        print green('done')
                    else:
                        if not self.verbose:
                            print red('\tFailed. ( error code %s) ' %
                                      (process.returncode))
                            os.chdir(self.curdir)

                        if not self.force:
                            raise RuntimeError()

                    if 'pylint' in cmd:
                        if outputs is not None:
                            for x in outputs.split('\n'):
                                if x.startswith('Your code has been'):
                                    print purple('\t%s' % x)
                    if 'nosetests' in cmd:
                        if errors is not None:
                            for x in errors.split('\n'):
                                if x.startswith('TOTAL'):
                                    res = x.replace('TOTAL', 'Total coverage')
                                    res = " ".join(res.split())
                                    print purple('\t%s' % res)
                                if x.startswith('Ran'):
                                    print purple('\t%s' % x)
                                if x.startswith('FAILED'):
                                    print purple('\t%s' % x)

        except RuntimeError:
            sys.exit()

        os.chdir(self.curdir)
Ejemplo n.º 4
0
    def run(self, color=True):
        """Enter in all package defined and Executing 'python setup.py' with
           user command.

        """
        import sys
        import os
        if color:
            try:
                from openalea.deploy.console import bold, red, green, \
                    color_terminal, nocolor, underline, purple
            except:
                try:
                    sys.path.insert(0, os.path.join('deploy', 'src', 'openalea', 'deploy'))
                    from console import bold, red, green, \
                        color_terminal, nocolor, underline, purple
                except:
                    pass
            if not color_terminal():
                # Windows' poor cmd box doesn't understand ANSI sequences
                nocolor()
        else:
            bold = purple = red = green = underline = str

        print bold("Running multisetup version %s" % __revision__.split()[2])

        project_dir = self.curdir.basename()
        directories = [self.curdir.joinpath(package) for package in self.packages]

        print 'Will process the following directories: ',
        for directory in directories:
            print bold(directory.basename()),
        print ''

        try:
            for directory in directories:
                try:
                    os.chdir(directory)
                    print underline('Entering %s package'
                                    % directory.basename())
                except OSError, e:
                    print underline('Entering %s package'
                                    % directory.basename()),
                    print red("cannot find this directory (%s)"
                              % directory.basename())
                    print e

                print 'Python exec : ', sys.executable

                #print underline('Entering %s package' % directory.basename())
                for cmd in self.commands:
                    setup_command = '%s setup.py %s ' % (sys.executable, cmd)
                    print "\tExecuting " + setup_command + '...processing',

                    #Run setup.py with user commands
                    outputs = None
                    errors = None
                    if self.verbose:
                        process = Popen(setup_command,
                                        shell=True)
                        status = process.wait()
                    else:
                        process = Popen(setup_command, stdout=PIPE, stderr=PIPE,
                                        shell=True)
                        #status = process.wait()
                        outputs, errors = process.communicate()
                    if process.returncode == 0:
                        print green('done')
                    else:
                        if not self.verbose:
                            print red('\tFailed. ( error code %s) ' %
                                  (process.returncode))
                            os.chdir(self.curdir)

                        if not self.force:
                            raise RuntimeError()

                    if 'pylint' in cmd:
                        if outputs is not None:
                            for x in outputs.split('\n'):
                                if x.startswith('Your code has been'):
                                    print purple('\t%s' % x)
                    if 'nosetests' in cmd:
                        if errors is not None:
                            for x in errors.split('\n'):
                                if x.startswith('TOTAL'):
                                    res = x.replace('TOTAL', 'Total coverage')
                                    res = " ".join(res.split())
                                    print purple('\t%s' % res)
                                if x.startswith('Ran'):
                                    print purple('\t%s' % x)
                                if x.startswith('FAILED'):
                                    print purple('\t%s' % x)

        except RuntimeError:
            sys.exit()

        os.chdir(self.curdir)