1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from __future__ import with_statement
17
18 import os
19 import copy
20 import stat
21 from twisted.python import usage, runtime
22
24 buildbot_tac = os.path.join(dir, "buildbot.tac")
25 if not os.path.isfile(buildbot_tac):
26 print "no buildbot.tac"
27 return False
28
29 with open(buildbot_tac, "r") as f:
30 contents = f.read()
31 return "Application('buildmaster')" in contents
32
34
35
36
37
38 buildbotOptions = None
39
40
41 requiredOptions = []
42
44
45
46
47
48
49
50 cls = self.__class__
51 if hasattr(cls, 'optParameters'):
52 old_optParameters = cls.optParameters
53 cls.optParameters = op = copy.deepcopy(cls.optParameters)
54 if self.buildbotOptions:
55 optfile = self.optionsFile = self.loadOptionsFile()
56 for optfile_name, option_name in self.buildbotOptions:
57 for i in range(len(op)):
58 if (op[i][0] == option_name
59 and optfile_name in optfile):
60 op[i] = list(op[i])
61 op[i][2] = optfile[optfile_name]
62 usage.Options.__init__(self, *args)
63 if hasattr(cls, 'optParameters'):
64 cls.optParameters = old_optParameters
65
67 """Find the .buildbot/options file. Crawl from the current directory
68 up towards the root, and also look in ~/.buildbot . The first directory
69 that's owned by the user and has the file we're looking for wins.
70 Windows skips the owned-by-user test.
71
72 @rtype: dict
73 @return: a dictionary of names defined in the options file. If no
74 options file was found, return an empty dict.
75 """
76
77 here = _here or os.path.abspath(os.getcwd())
78
79 if runtime.platformType == 'win32':
80
81 from win32com.shell import shellcon, shell
82 appdata = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
83 home = os.path.join(appdata, "buildbot")
84 else:
85 home = os.path.expanduser("~/.buildbot")
86
87 searchpath = []
88 toomany = 20
89 while True:
90 searchpath.append(os.path.join(here, ".buildbot"))
91 next = os.path.dirname(here)
92 if next == here:
93 break
94 here = next
95 toomany -= 1
96 if toomany == 0:
97 print ("I seem to have wandered up into the infinite glories "
98 "of the heavens. Oops.")
99 break
100
101 searchpath.append(home)
102
103 localDict = {}
104
105 for d in searchpath:
106 if os.path.isdir(d):
107 if runtime.platformType != 'win32':
108 if os.stat(d)[stat.ST_UID] != os.getuid():
109 print "skipping %s because you don't own it" % d
110 continue
111 optfile = os.path.join(d, "options")
112 if os.path.exists(optfile):
113 try:
114 with open(optfile, "r") as f:
115 options = f.read()
116 exec options in localDict
117 except:
118 print "error while reading %s" % optfile
119 raise
120 break
121
122 for k in localDict.keys():
123 if k.startswith("__"):
124 del localDict[k]
125 return localDict
126
127 - def postOptions(self):
128 missing = [ k for k in self.requiredOptions if self[k] is None ]
129 if missing:
130 if len(missing) > 1:
131 msg = 'Required arguments missing: ' + ', '.join(missing)
132 else:
133 msg = 'Required argument missing: ' + missing[0]
134 raise usage.UsageError(msg)
135
137
138 """SubcommandOptions Mixin to handle subcommands that take a basedir
139 argument"""
140
142 if len(args) > 0:
143 self['basedir'] = args[0]
144 else:
145
146 self['basedir'] = os.getcwd()
147 if len(args) > 1:
148 raise usage.UsageError("I wasn't expecting so many arguments")
149
150 - def postOptions(self):
151
152
153 self['basedir'] = os.path.abspath(os.path.expanduser(self['basedir']))
154