aboutsummaryrefslogtreecommitdiff
blob: 9aafe7de58946a007c2613bc992c495844a9a733 (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
#! /usr/bin/python2
#
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
#
# Licensed under the GNU General Public License, v2
#
# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/bsfix/bsfix.py,v 1.1 2004/12/20 19:13:05 karltk Exp $

import os
import re
import sys
import optparse

import javatoolkit.parser as parser
from javatoolkit.classpath import Classpath
       
def find_best_version(path, vers):
    for ver in vers:
        x = re.sub("[0-9].[0-9].[0-9]", ver, path)
        if os.path.exists(x):
            return ver
    return None

"""
Parse command line arguments.
"""
def parse_args(args):

	basedir = os.getcwd()

	parser = optparse.OptionParser(version="%prog " + __version__ )

	parser.add_option("-a", "--attribute", dest="attribute", 
			default="", help="select this attribute")

	parser.add_option("-r", "--replace", dest="replace", 
			default=".", help="where to store the generated files")

	parser.add_option("-c", "--cache-file", dest="cachefile",
			default=basedir + "/cache3.db", help="where to store the cache")

	parser.add_option("-m", "--manifest-file", dest="manifestfile",
			default=basedir + "/manifest.synctool", help="where to store the manifest file")

	parser.add_option("-u", "--update-mode", dest="update_mode",
			default="quick", help="update mode, either 'generate' or 'quick'")

	parser.add_option("-v", "--verbose", dest="verbosity",
			default=3, help="verbosity")

	return parser.parse_args()

		        
if __name__ == "__main__":

    infile = sys.argv[1]
    r = parser.buildproperties.parse(open(infile))

    alt_versions = sys.argv[2:]
    
    n = parser.find_node(r, "eclipse_classpath")
    cp = Classpath(n.value)

    for i in range(len(cp)):
        x = cp[i]
        t = parser.expand(r, x)
        if t.startswith("/usr/lib/eclipse-3"):
            ver = find_best_version(t, alt_versions)
            if ver is None:
                print "Failed to resolve " + x
                sys.exit(2)
                
            y = re.sub("[0-9].[0-9].[0-9]", ver, x)
            cp[i] = y

    n.value = str(cp)
    
    r.dump()