summaryrefslogtreecommitdiffstats
path: root/cnucnu/checkshell.py
blob: 8f6f9b537bf30c1092ee85c865af02b63980931a (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/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/>.
# }}}

import sys
import cmd
import readline

from package_list import Package, PackageList, Repository
from bugzilla_reporter import BugzillaReporter
from helper import pprint
from cvs import CVS

class CheckShell(cmd.Cmd):
    def __init__(self, config):
        cmd.Cmd.__init__(self)
        readline.set_completer_delims(' ')

        self.repo = Repository()
        self.package = Package("", None, None, self.repo)
        self._package_list = None
        self.prompt_default = " URL:"
        self.update_prompt()
        self.config = config
        self._br = None
        self.cvs = CVS()

    @property
    def package_list(self):
        if not self._package_list:
            self._package_list = PackageList(repo=self.repo)
            if self.package.name:
                self._package_list.append(self.package)
        return self._package_list

    @property
    def br(self):
        if not self._br:
            bugzilla_config = self.config.bugzilla_config
            try:
                self._br = BugzillaReporter(bugzilla_config)
            
            except Exception, e:
                print "Cannot query bugzilla, maybe config is faulty or missing", repr(e), dict(e), str(e)
        return self._br

    def update_prompt(self):
        self.prompt = "%(name)s %(regex)s %(url)s " % self.package
        self.prompt += "%s> " % self.prompt_default

    def do_url(self, args):
        self.package.url = args

    def do_name(self, args):
        self.package = Package(args, self.package.regex, self.package.name, self.repo)
        if not self.package.regex:
            self.package.regex = "DEFAULT"
        if not self.package.url:
            self.package.url = "SF-DEFAULT"

    def do_fm(self, args):
        self.package.name = args
        self.package.regex = "FM-DEFAULT"
        self.package.url = "FM-DEFAULT"

    def do_report(self, args):
        pprint(self.package.report_outdated(dry_run))

    def do_inspect(self, args):
        try:
            self.package = self.package_list[args]
        except KeyError, ke:
            print ke

    def complete_inspect(self, text, line, begidx, endidx):
        package_names = [p.name for p in self.package_list if p.name.startswith(text)]
        return package_names
    
    def do_regex(self, args):
        self.package.regex = args

    def do_EOF(self, args):
        self.emptyline()


    def emptyline(self):
        if self.package.url:
            self.package.url = None
        else:
            print
            sys.exit(0)

    def default(self, args):
        if not self.package.url:
            self.do_url(args)
        else:
            self.do_regex(args)

    def postcmd(self, stop, line):
        if not self.package.url:
            self.prompt_default = " URL:"
        else:
            self.prompt_default = " Regex:"

        self.update_prompt()
        if self.package.url and self.package.regex:
            print "Upstream Versions:", self.package.upstream_versions
            print "Latest:", self.package.latest_upstream

            if self.package.name:
                print "%(repo_name)s Version: %(repo_version)s %(repo_release)s %(status)s" % self.package

                sourcefile = self.package.upstream_version_in_cvs
                if sourcefile:
                    print "Found in CVS:", sourcefile
                else:
                    print "Not Found in CVS"
                bug = self.package.exact_outdated_bug
                if bug:
                    print "Exact Bug:", "%s %s:%s" % (self.br.bug_url(bug), bug.bug_status, bug.summary)
                bug = self.package.open_outdated_bug
                if bug:
                    print "Open Bug:", "%s %s:%s" % (self.br.bug_url(bug), bug.bug_status, bug.summary)
        return stop