Пример #1
0
    def run(self):
        # We always start with Copyright
        self.current_section = RpmCopyright(self.specfile)

        # FIXME: we need to store the content localy and then reorder
        #        to maintain the specs all the same (eg somebody put
        #        filelist to the top).
        for line in self.fin:
            # Stop at the end of the file
            if len(line) == 0:
                break
            # Remove \n to make it easier to parse things
            line = line.rstrip('\n')
            line = line.rstrip('\r')

            new_class = self._detect_new_section(line)
            # Following line is debug output with class info
            # USE: 'spec-cleaner file > /dev/null' to see the stderr output
            #sys.stderr.write("class: '{0}' line: '{1}'\n".format(new_class, line))
            if new_class:
                # We don't want to print newlines before %else and %endif
                if new_class == Section and self.reg.re_else.match(
                        line) or self.reg.re_endif.match(line):
                    newline = False
                else:
                    newline = True
                self.current_section.output(self.fout, newline)
                # we need to sent pkgconfig option to preamble and package
                if new_class == RpmPreamble or new_class == RpmPackage:
                    self.current_section = new_class(self.specfile,
                                                     self.pkgconfig)
                else:
                    self.current_section = new_class(self.specfile)
                # skip empty line adding if we are switching sections
                if self._previous_line == '' and line == '':
                    continue

            # Do not store data from clean and skip out here
            if isinstance(self.current_section, RpmClean):
                continue

            self.current_section.add(line)
            self._previous_line = line
            if line != '' or not line.startswith('#'):
                self._previous_nonempty_line = line

        self.current_section.output(self.fout)
        self.fout.flush()

        if self.diff:
            cmd = shlex.split(self.diff_prog + " " +
                              self.specfile.replace(" ", "\\ ") + " " +
                              self.fout.name.replace(" ", "\\ "))
            try:
                subprocess.call(cmd, shell=False)
            except OSError as e:
                raise RpmException('Could not execute %s (%s)' %
                                   (self.diff_prog.split()[0], e.strerror))
Пример #2
0
    def run(self):
        # We always start with Copyright
        self.current_section = RpmCopyright(self.specfile)

        # FIXME: we need to store the content localy and then reorder
        #        to maintain the specs all the same (eg somebody put
        #        filelist to the top).
        for line in self.fin:
            # Stop at the end of the file
            if len(line) == 0:
                break
            # Remove \n to make it easier to parse things
            line = line.rstrip('\n')
            line = line.rstrip('\r')

            new_class = self._detect_new_section(line)
            if new_class:
                self.current_section.output(self.fout)
                # we need to sent pkgconfig option to preamble and package
                if new_class == RpmPreamble or new_class == RpmPackage:
                    self.current_section = new_class(self.specfile,
                                                     self.pkgconfig)
                else:
                    self.current_section = new_class(self.specfile)

            self.current_section.add(line)
            self._previous_line = line
            if line != '' or not line.startswith('#'):
                self._previous_nonempty_line = line

        self.current_section.output(self.fout)
        self.fout.flush()

        if self.diff:
            cmd = shlex.split(self.diff_prog + " " +
                              self.specfile.replace(" ", "\\ ") + " " +
                              self.fout.name.replace(" ", "\\ "))
            try:
                subprocess.call(cmd, shell=False)
            except OSError as e:
                raise RpmException('Could not execute %s (%s)' %
                                   (self.diff_prog.split()[0], e.strerror))