summaryrefslogtreecommitdiffstats
path: root/cnucnu/cvs.py
blob: bc19d93cb9648127192365a060438577734fc023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
# vim: fileencoding=utf8 foldmethod=marker
# {{{ License header: GPLv2+
#    This file is part of cnucnu.
#
#    Cnucnu is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 2 of the License, or
#    (at your option) any later version.
#
#    Cnucnu is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with cnucnu.  If not, see <http://www.gnu.org/licenses/>.
# }}}

# Options: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

import pycurl
import StringIO
from helper import secure_download
from config import Config

class CVS(object):
    """ cainfo: filename :-/
    """ 
    def __init__(self, viewvc_url="", cainfo=""):
        defaults = Config().config["cvs"]

        if not viewvc_url:
            viewvc_url = defaults["viewvc_url"]

        if not cainfo:
            cainfo = defaults["cainfo"]

        self.viewvc_url = viewvc_url
        self.cainfo = cainfo

    def get_sources(self, package):
        return secure_download(self.viewvc_url % package, cainfo=self.cainfo)

    def get_sourcefiles(self, package):
        sources = self.get_sources(package)
        sourcefiles = []
        for line in sources.split("\n"):
            if line != "":
                file = line.split(" ")[2]
                sourcefiles.append(file)

        return sourcefiles

    def has_upstream_version(self, package):
        sourcefiles = self.get_sourcefiles(package)
        for file in sourcefiles:
            if package.latest_upstream in file:
                return True
        return False



if __name__ == '__main__':
    cvs = CVS(**{"viewvc_url": "https://cvs.fedoraproject.org/viewvc/rpms/%(name)s/devel/sources?revision=HEAD", "cainfo": "fedora-server-ca.cert"})

    from package_list import Package, Repository



    package = Package("crossvc", "", "", Repository())
    package._latest_upstream = "1.5.2-0"

    print cvs.get_sources({"name": "crossvc"})
    print cvs.get_sourcefiles({"name": "crossvc"})
    print cvs.has_upstream_version(package)