diff options
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 60 |
1 files changed, 58 insertions, 2 deletions
| @@ -29,6 +29,7 @@ import sys | |||
| 29 | import urllib2 | 29 | import urllib2 |
| 30 | 30 | ||
| 31 | from trace import SetTrace | 31 | from trace import SetTrace |
| 32 | from git_command import git, GitCommand | ||
| 32 | from git_config import init_ssh, close_ssh | 33 | from git_config import init_ssh, close_ssh |
| 33 | from command import InteractiveCommand | 34 | from command import InteractiveCommand |
| 34 | from command import MirrorSafeCommand | 35 | from command import MirrorSafeCommand |
| @@ -134,6 +135,9 @@ class _Repo(object): | |||
| 134 | print >>sys.stderr, 'error: no project in current directory' | 135 | print >>sys.stderr, 'error: no project in current directory' |
| 135 | sys.exit(1) | 136 | sys.exit(1) |
| 136 | 137 | ||
| 138 | def _MyRepoPath(): | ||
| 139 | return os.path.dirname(__file__) | ||
| 140 | |||
| 137 | def _MyWrapperPath(): | 141 | def _MyWrapperPath(): |
| 138 | return os.path.join(os.path.dirname(__file__), 'repo') | 142 | return os.path.join(os.path.dirname(__file__), 'repo') |
| 139 | 143 | ||
| @@ -200,11 +204,63 @@ def _PruneOptions(argv, opt): | |||
| 200 | continue | 204 | continue |
| 201 | i += 1 | 205 | i += 1 |
| 202 | 206 | ||
| 207 | _user_agent = None | ||
| 208 | |||
| 209 | def _UserAgent(): | ||
| 210 | global _user_agent | ||
| 211 | |||
| 212 | if _user_agent is None: | ||
| 213 | py_version = sys.version_info | ||
| 214 | |||
| 215 | os_name = sys.platform | ||
| 216 | if os_name == 'linux2': | ||
| 217 | os_name = 'Linux' | ||
| 218 | elif os_name == 'win32': | ||
| 219 | os_name = 'Win32' | ||
| 220 | elif os_name == 'cygwin': | ||
| 221 | os_name = 'Cygwin' | ||
| 222 | elif os_name == 'darwin': | ||
| 223 | os_name = 'Darwin' | ||
| 224 | |||
| 225 | p = GitCommand( | ||
| 226 | None, ['describe', 'HEAD'], | ||
| 227 | cwd = _MyRepoPath(), | ||
| 228 | capture_stdout = True) | ||
| 229 | if p.Wait() == 0: | ||
| 230 | repo_version = p.stdout | ||
| 231 | if len(repo_version) > 0 and repo_version[-1] == '\n': | ||
| 232 | repo_version = repo_version[0:-1] | ||
| 233 | if len(repo_version) > 0 and repo_version[0] == 'v': | ||
| 234 | repo_version = repo_version[1:] | ||
| 235 | else: | ||
| 236 | repo_version = 'unknown' | ||
| 237 | |||
| 238 | _user_agent = 'git-repo/%s (%s) git/%s Python/%d.%d.%d' % ( | ||
| 239 | repo_version, | ||
| 240 | os_name, | ||
| 241 | '.'.join(map(lambda d: str(d), git.version_tuple())), | ||
| 242 | py_version[0], py_version[1], py_version[2]) | ||
| 243 | return _user_agent | ||
| 244 | |||
| 245 | class _UserAgentHandler(urllib2.BaseHandler): | ||
| 246 | def http_request(self, req): | ||
| 247 | req.add_header('User-Agent', _UserAgent()) | ||
| 248 | return req | ||
| 249 | |||
| 250 | def https_request(self, req): | ||
| 251 | req.add_header('User-Agent', _UserAgent()) | ||
| 252 | return req | ||
| 253 | |||
| 203 | def init_http(): | 254 | def init_http(): |
| 255 | handlers = [_UserAgentHandler()] | ||
| 256 | |||
| 204 | if 'http_proxy' in os.environ: | 257 | if 'http_proxy' in os.environ: |
| 205 | url = os.environ['http_proxy'] | 258 | url = os.environ['http_proxy'] |
| 206 | proxy_support = urllib2.ProxyHandler({'http': url, 'https': url}) | 259 | handlers.append(urllib2.ProxyHandler({'http': url, 'https': url})) |
| 207 | urllib2.install_opener(urllib2.build_opener(proxy_support)) | 260 | if 'REPO_CURL_VERBOSE' in os.environ: |
| 261 | handlers.append(urllib2.HTTPHandler(debuglevel=1)) | ||
| 262 | handlers.append(urllib2.HTTPSHandler(debuglevel=1)) | ||
| 263 | urllib2.install_opener(urllib2.build_opener(*handlers)) | ||
| 208 | 264 | ||
| 209 | def _Main(argv): | 265 | def _Main(argv): |
| 210 | opt = optparse.OptionParser(usage="repo wrapperinfo -- ...") | 266 | opt = optparse.OptionParser(usage="repo wrapperinfo -- ...") |
