예제 #1
0
    def do_rss(self, repo_data, latest):
        """
        Write the RSS feed.
        
        @param repo_data: the dict containing repository data
        @type  repo_data: dict
        @param latest:    the list of tuples returned by get_latest_packages
        @type  latest:    list
        
        @rtype: void
        """
        self.say('Generating rss feed...')
        etb = TreeBuilder()
        out = os.path.join(self.outdir, RSSFILE)
        etb.start('rss', {'version': '2.0'})
        etb.start('channel')
        etb.start('title')
        etb.data(repo_data['title'])
        etb.end('title')
        etb.start('link')
        etb.data('%s/repoview/%s' % (self.opts.url, RSSFILE))
        etb.end('link')
        etb.start('description')
        etb.data('Latest packages for %s' % repo_data['title'])
        etb.end('description')
        etb.start('lastBuildDate')
        etb.data(time.strftime(ISOFORMAT))
        etb.end('lastBuildDate')
        etb.start('generator')
        etb.data('Repoview-%s' % repo_data['my_version'])
        etb.end('generator')

        rss_tpt = os.path.join(self.opts.templatedir, RSSKID)
        rss_kid = Template(file=rss_tpt)
        rss_kid.assume_encoding = "utf-8"
        rss_kid.repo_data = repo_data
        rss_kid.url = self.opts.url

        for row in latest:
            pkg_data = self.get_package_data(row[0])

            rpm = pkg_data['rpms'][0]
            (epoch, version, release, arch, built) = rpm[:5]
            etb.start('item')
            etb.start('guid')
            etb.data('%s/repoview/%s+%s:%s-%s.%s' %
                     (self.opts.url, pkg_data['filename'], epoch, version,
                      release, arch))
            etb.end('guid')
            etb.start('link')
            etb.data('%s/repoview/%s' % (self.opts.url, pkg_data['filename']))
            etb.end('link')
            etb.start('pubDate')
            etb.data(time.strftime(ISOFORMAT, time.gmtime(int(built))))
            etb.end('pubDate')
            etb.start('title')
            etb.data('Update: %s-%s-%s' % (pkg_data['name'], version, release))
            etb.end('title')
            rss_kid.pkg_data = pkg_data
            description = rss_kid.serialize()
            etb.start('description')
            etb.data(description.decode('utf-8'))
            etb.end('description')
            etb.end('item')

        etb.end('channel')
        etb.end('rss')
        rss = etb.close()

        etree = ElementTree(rss)
        out = os.path.join(self.outdir, RSSFILE)
        etree.write(out, 'utf-8')
        self.say('done\n')
예제 #2
0
 def do_rss(self, repo_data, latest):
     """
     Write the RSS feed.
     
     @param repo_data: the dict containing repository data
     @type  repo_data: dict
     @param latest:    the list of tuples returned by get_latest_packages
     @type  latest:    list
     
     @rtype: void
     """
     self.say('Generating rss feed...')
     etb = TreeBuilder()
     out = os.path.join(self.outdir, RSSFILE)
     etb.start('rss', {'version': '2.0'})
     etb.start('channel')
     etb.start('title')
     etb.data(repo_data['title'])
     etb.end('title')
     etb.start('link')
     etb.data('%s/repoview/%s' % (self.opts.url, RSSFILE))
     etb.end('link')
     etb.start('description')
     etb.data('Latest packages for %s' % repo_data['title'])
     etb.end('description')
     etb.start('lastBuildDate')
     etb.data(time.strftime(ISOFORMAT))
     etb.end('lastBuildDate')
     etb.start('generator')
     etb.data('Repoview-%s' % repo_data['my_version'])
     etb.end('generator')
     
     rss_tpt = os.path.join(self.opts.templatedir, RSSKID)
     rss_kid = Template(file=rss_tpt)
     rss_kid.assume_encoding = "utf-8"
     rss_kid.repo_data = repo_data
     rss_kid.url = self.opts.url
     
     for row in latest:
         pkg_data = self.get_package_data(row[0])
         
         rpm = pkg_data['rpms'][0]
         (epoch, version, release, arch, built) = rpm[:5]
         etb.start('item')
         etb.start('guid')
         etb.data('%s/repoview/%s+%s:%s-%s.%s' % (self.opts.url, 
                                                  pkg_data['filename'], 
                                                  epoch, version, release, 
                                                  arch))
         etb.end('guid')
         etb.start('link')
         etb.data('%s/repoview/%s' % (self.opts.url, pkg_data['filename']))
         etb.end('link')
         etb.start('pubDate')
         etb.data(time.strftime(ISOFORMAT, time.gmtime(int(built))))
         etb.end('pubDate')
         etb.start('title')
         etb.data('Update: %s-%s-%s' % (pkg_data['name'], version, release))
         etb.end('title')
         rss_kid.pkg_data = pkg_data
         description = rss_kid.serialize()
         etb.start('description')
         etb.data(description.decode('utf-8'))
         etb.end('description')
         etb.end('item')
     
     etb.end('channel')
     etb.end('rss')
     rss = etb.close()
     
     etree = ElementTree(rss)
     out = os.path.join(self.outdir, RSSFILE)
     etree.write(out, 'utf-8')
     self.say('done\n')
예제 #3
0
    def __init__(self, opts):
        """
        @param opts: OptionParser's opts
        @type  opts: OptionParser
        """
        # list of files to remove at the end of processing
        self.cleanup = []
        self.opts = opts
        self.outdir = os.path.join(opts.repodir, 'repoview')

        self.exclude = '1=1'
        self.state_data = {}  #?
        self.written = {}  #?

        self.groups = []
        self.letter_groups = []

        self.pconn = None  # primary.sqlite
        self.oconn = None  # other.sqlite
        self.sconn = None  # state db

        self.setup_repo()
        self.setup_outdir()
        self.setup_state_db()
        self.setup_excludes()

        if not self.groups:
            self.setup_rpm_groups()

        letters = self.setup_letter_groups()

        repo_data = {
            'title': opts.title,
            'letters': letters,
            'my_version': VERSION
        }

        group_kid = Template(file=os.path.join(opts.templatedir, GRPKID))
        group_kid.assume_encoding = "utf-8"
        group_kid.repo_data = repo_data
        self.group_kid = group_kid

        pkg_kid = Template(file=os.path.join(opts.templatedir, PKGKID))
        pkg_kid.assume_encoding = "utf-8"
        pkg_kid.repo_data = repo_data
        self.pkg_kid = pkg_kid

        count = 0
        for group_data in self.groups + self.letter_groups:
            (grp_name, grp_filename, grp_description, pkgnames) = group_data
            pkgnames.sort()

            group_data = {
                'name': grp_name,
                'description': grp_description,
                'filename': grp_filename,
            }

            packages = self.do_packages(repo_data, group_data, pkgnames)

            if not packages:
                # Empty groups are ignored
                del self.groups[count]
                continue

            count += 1

            group_data['packages'] = packages

            checksum = self.mk_checksum(repo_data, group_data)
            if self.has_changed(grp_filename, checksum):
                # write group file
                self.say('Writing group %s\n' % grp_filename)
                self.group_kid.group_data = group_data
                outfile = os.path.join(self.outdir, grp_filename)
                self.group_kid.write(outfile, output='xhtml-strict')

        latest = self.get_latest_packages()
        repo_data['latest'] = latest
        repo_data['groups'] = self.groups

        checksum = self.mk_checksum(repo_data)
        if self.has_changed('index.html', checksum):
            # Write index.html and rss feed (if asked)
            self.say('Writing index.html...')
            idx_tpt = os.path.join(self.opts.templatedir, IDXKID)
            idx_kid = Template(file=idx_tpt)
            idx_kid.assume_encoding = "utf-8"
            idx_kid.repo_data = repo_data
            idx_kid.url = self.opts.url
            idx_kid.latest = latest
            idx_kid.groups = self.groups
            outfile = os.path.join(self.outdir, 'index.html')
            idx_kid.write(outfile, output='xhtml-strict')
            self.say('done\n')

            # rss feed
            if self.opts.url:
                self.do_rss(repo_data, latest)

        self.remove_stale()
        self.sconn.commit()
예제 #4
0
 def __init__(self, opts):
     """
     @param opts: OptionParser's opts
     @type  opts: OptionParser
     """
     # list of files to remove at the end of processing
     self.cleanup = []
     self.opts    = opts
     self.outdir  = os.path.join(opts.repodir, 'repoview')
     
     self.exclude    = '1=1'
     self.state_data = {} #?
     self.written    = {} #?
     
     self.groups        = []
     self.letter_groups = []
     
     self.pconn = None # primary.sqlite
     self.oconn = None # other.sqlite
     self.sconn = None # state db
     
     self.setup_repo()
     self.setup_outdir()
     self.setup_state_db()
     self.setup_excludes()
     
     if not self.groups:
         self.setup_rpm_groups()
     
     letters = self.setup_letter_groups()
     
     repo_data = {
                  'title':      opts.title,
                  'letters':    letters,
                  'my_version': VERSION
                 }
     
     group_kid = Template(file=os.path.join(opts.templatedir, GRPKID))
     group_kid.assume_encoding = "utf-8"
     group_kid.repo_data = repo_data
     self.group_kid = group_kid
     
     pkg_kid = Template(file=os.path.join(opts.templatedir, PKGKID))
     pkg_kid.assume_encoding = "utf-8"
     pkg_kid.repo_data = repo_data
     self.pkg_kid = pkg_kid
     
     count = 0
     for group_data in self.groups + self.letter_groups:
         (grp_name, grp_filename, grp_description, pkgnames) = group_data
         pkgnames.sort()
         
         group_data = {
                       'name':        grp_name,
                       'description': grp_description,
                       'filename':    grp_filename,
                       }
         
         packages = self.do_packages(repo_data, group_data, pkgnames)
         
         if not packages:
             # Empty groups are ignored
             del self.groups[count]
             continue
         
         count += 1
         
         group_data['packages'] = packages
         
         checksum = self.mk_checksum(repo_data, group_data)
         if self.has_changed(grp_filename, checksum):
             # write group file
             self.say('Writing group %s\n' % grp_filename)
             self.group_kid.group_data = group_data
             outfile = os.path.join(self.outdir, grp_filename)
             self.group_kid.write(outfile, output='xhtml-strict')
     
     latest = self.get_latest_packages()
     repo_data['latest'] = latest
     repo_data['groups'] = self.groups
     
     checksum = self.mk_checksum(repo_data)
     if self.has_changed('index.html', checksum):
         # Write index.html and rss feed (if asked)
         self.say('Writing index.html...')
         idx_tpt = os.path.join(self.opts.templatedir, IDXKID)
         idx_kid = Template(file=idx_tpt)
         idx_kid.assume_encoding = "utf-8"
         idx_kid.repo_data = repo_data
         idx_kid.url = self.opts.url
         idx_kid.latest = latest
         idx_kid.groups = self.groups
         outfile = os.path.join(self.outdir, 'index.html')
         idx_kid.write(outfile, output='xhtml-strict')
         self.say('done\n')
         
         # rss feed
         if self.opts.url:
             self.do_rss(repo_data, latest)
     
     self.remove_stale()
     self.sconn.commit()