~bughelper-dev/bughelper/main

8 by Daniel Holbach
added bugescape tool
1
#!/usr/bin/env python
2
3
# Written by Henrik Nilsen Omma
4
# (C) Canonical, Ltd. Licensed under the GPL
5
10 by Daniel Holbach
cleaned up a bit
6
try:
7
    import XMLOperations
29 by Daniel Holbach
bugxml -sa works now (Bug #79220)
8
    import utils
48 by Daniel Holbach
reverted r47
9
    from commandLine import commandLine
54.1.1 by Daniel Holbach
- removed clue files from the branch
10
    import config as config
10 by Daniel Holbach
cleaned up a bit
11
except:
48 by Daniel Holbach
reverted r47
12
    from bugHelper.commandLine import commandLine
10 by Daniel Holbach
cleaned up a bit
13
    import bugHelper.XMLOperations as XMLOperations
54.1.1 by Daniel Holbach
- removed clue files from the branch
14
    import bugHelper.config as config
188.3.16 by Brian Murray
--help and manual cleanup
15
    import launchpadbugs.utils as utils
10 by Daniel Holbach
cleaned up a bit
16
112 by Daniel Holbach
commit Markus Korn's patch to use urllib2 which gives us advantages in dealing with timeouts, etc.
17
import urllib2
8 by Daniel Holbach
added bugescape tool
18
import sys
9 by Daniel Holbach
added RelaxNG schema and generalized bugescape to become a bug xml tool
19
import os
20
8 by Daniel Holbach
added bugescape tool
21
def main():
54.1.1 by Daniel Holbach
- removed clue files from the branch
22
    conf = config.Config("~/.bughelper/config")
32 by Daniel Holbach
committed modified version of a patch of Fernando Ribeiro <fernando@staff.nerdgroup.org> to fix bug #79215: made variable names more consistent and telling, use 4 space indentation throughout, lines are only 79 char long, dropped --all option (on request of Sébastien Bacher <seb128@ubuntu.com>), added Fernando to contributors, tried to stick closer to PEP-8
23
    cl = commandLine()
35 by Daniel Holbach
fixed bugxml commandline usage, thanks Dean Sas <dean@deansas.org> for the sharp eye
24
    
25
    if not cl.options.text and not cl.options.add and \
26
       not cl.options.cluefile:
27
        cl.parser.print_usage()
28
        sys.exit(1)
32 by Daniel Holbach
committed modified version of a patch of Fernando Ribeiro <fernando@staff.nerdgroup.org> to fix bug #79215: made variable names more consistent and telling, use 4 space indentation throughout, lines are only 79 char long, dropped --all option (on request of Sébastien Bacher <seb128@ubuntu.com>), added Fernando to contributors, tried to stick closer to PEP-8
29
30
    if cl.options.text:
112 by Daniel Holbach
commit Markus Korn's patch to use urllib2 which gives us advantages in dealing with timeouts, etc.
31
        print "COPY:  %s " % (urllib2.quote(''.join(cl.options.text), safe=' '))
32
        print "Will be unquoted: %s" % (urllib2.unquote(''.join(cl.options.text)))
32 by Daniel Holbach
committed modified version of a patch of Fernando Ribeiro <fernando@staff.nerdgroup.org> to fix bug #79215: made variable names more consistent and telling, use 4 space indentation throughout, lines are only 79 char long, dropped --all option (on request of Sébastien Bacher <seb128@ubuntu.com>), added Fernando to contributors, tried to stick closer to PEP-8
33
        sys.exit(0)
34
35 by Daniel Holbach
fixed bugxml commandline usage, thanks Dean Sas <dean@deansas.org> for the sharp eye
35
    if cl.options.add:
63.1.3 by Daniel Holbach
added --dontlist to ./bugxml, which adds a <dontlist> tag so that the 'master' duplicate bugs don't get listed
36
        dontlist = set()
37
        if cl.options.dontlist:
38
            dontlist.update(cl.options.dontlist.split(","))
32 by Daniel Holbach
committed modified version of a patch of Fernando Ribeiro <fernando@staff.nerdgroup.org> to fix bug #79215: made variable names more consistent and telling, use 4 space indentation throughout, lines are only 79 char long, dropped --all option (on request of Sébastien Bacher <seb128@ubuntu.com>), added Fernando to contributors, tried to stick closer to PEP-8
39
        package = cl.options.add[0]
112 by Daniel Holbach
commit Markus Korn's patch to use urllib2 which gives us advantages in dealing with timeouts, etc.
40
        condition = urllib2.quote(''.join(cl.options.add[1]), safe=' ')
41
        clue = urllib2.quote(''.join(cl.options.add[2]), safe=' ')
35 by Daniel Holbach
fixed bugxml commandline usage, thanks Dean Sas <dean@deansas.org> for the sharp eye
42
        # We do not fail here, because 'global clues' are not bound to
43
        # source package names.
32 by Daniel Holbach
committed modified version of a patch of Fernando Ribeiro <fernando@staff.nerdgroup.org> to fix bug #79215: made variable names more consistent and telling, use 4 space indentation throughout, lines are only 79 char long, dropped --all option (on request of Sébastien Bacher <seb128@ubuntu.com>), added Fernando to contributors, tried to stick closer to PEP-8
44
        if not utils.package_exists(package):
35 by Daniel Holbach
fixed bugxml commandline usage, thanks Dean Sas <dean@deansas.org> for the sharp eye
45
            print "Warning: Package '%s' does not exist." % package
83 by Daniel Holbach
committed modified patch by Torsten Spindler <torsten@canonical.com>
46
        if conf.local_packages_dir:
47
            XMLOperations.add_simple_clue(package, condition, clue, 
48
                                          conf.local_packages_dir.strip(), 
49
                                          dontlist)
50
            sys.exit(0)
51
        else:
84 by Daniel Holbach
- warn and don't fail on invalid XML, LP: #85150
52
            print "Error: Please define Local-Packages-Dir in ~/.bughelper/config"
83 by Daniel Holbach
committed modified patch by Torsten Spindler <torsten@canonical.com>
53
            sys.exit(1)
9 by Daniel Holbach
added RelaxNG schema and generalized bugescape to become a bug xml tool
54
    
35 by Daniel Holbach
fixed bugxml commandline usage, thanks Dean Sas <dean@deansas.org> for the sharp eye
55
    if cl.options.cluefile:
36 by Daniel Holbach
fixed bugxml -v commandline usage, thanks Dean Sas again
56
        xml_file = cl.options.cluefile
150 by Daniel Holbach
Markus Korn fixed bug 107959
57
        if not cl.options.cluefile or not os.path.exists(os.path.abspath(xml_file)):
58
            if not os.path.exists(os.path.join(conf.local_packages_dir.strip(),xml_file)):
59
                print "Neither %s nor %s exist." % (os.path.abspath(xml_file),
60
                                           os.path.normpath(os.path.join(conf.local_packages_dir.strip(),xml_file)))
9 by Daniel Holbach
added RelaxNG schema and generalized bugescape to become a bug xml tool
61
                sys.exit(1)
62
            else:
150 by Daniel Holbach
Markus Korn fixed bug 107959
63
                xml_file = os.path.join(conf.local_packages_dir.strip(),xml_file)
145 by Daniel Holbach
fix bug 107735
64
        
65
        schema = XMLOperations.find_schema(conf.local_packages_dir.strip(), 
66
                                           XMLOperations.get_clue_file_version(xml_file))
67
        if not schema:
68
            print "Schema file not found."
69
            sys.exit(1)
9 by Daniel Holbach
added RelaxNG schema and generalized bugescape to become a bug xml tool
70
29 by Daniel Holbach
bugxml -sa works now (Bug #79220)
71
        if not XMLOperations.rng_validate(schema, xml_file):
72
            print "%s does not validate against %s." % (xml_file, schema)
73
        else:
74
            print "Success: %s validates against %s." % (xml_file, schema)
9 by Daniel Holbach
added RelaxNG schema and generalized bugescape to become a bug xml tool
75
8 by Daniel Holbach
added bugescape tool
76
77
if __name__ == "__main__":
78
    main()
79