[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 2 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 3 | # repo default configuration |
| 4 | # |
| 5 | import os |
| 6 | REPO_URL = os.environ.get('REPO_URL', None) |
| 7 | if not REPO_URL: |
| 8 | REPO_URL = 'https://chromium.googlesource.com/external/repo' |
| 9 | REPO_REV = 'stable' |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 10 | |
| 11 | # Copyright (C) 2008 Google Inc. |
| 12 | # |
| 13 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | # you may not use this file except in compliance with the License. |
| 15 | # You may obtain a copy of the License at |
| 16 | # |
| 17 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | # |
| 19 | # Unless required by applicable law or agreed to in writing, software |
| 20 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | # See the License for the specific language governing permissions and |
| 23 | # limitations under the License. |
| 24 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 25 | # increment this whenever we make important changes to this script |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 26 | VERSION = (1, 23) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 27 | |
| 28 | # increment this if the MAINTAINER_KEYS block is modified |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 29 | KEYRING_VERSION = (1, 5) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 30 | MAINTAINER_KEYS = """ |
| 31 | |
| 32 | Repo Maintainer <[email protected]> |
| 33 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 34 | Version: GnuPG v1.4.2.2 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ILMFF1BRk/ |
| 66 | 0V7wCL+68UwwiQDvyMOQuqkysKLSDCLb7BFcyA7j6KG+5hpsREstFX2wK1yKeraz |
| 67 | 5xGrFy8tfAaeBMIQ17gvFSp/suc9DYO0ICK2BISzq+F+ZiAKsjMYOBNdH/h0zobQ |
| 68 | HTHs37+/QLMomGEGKZMWi0dShU2J5mNRQu3Hhxl3hHDVbt5CeJBb26aQcQrFz69W |
| 69 | zE3GNvmJosh6leayjtI9P2A6iEkEGBECAAkFAkj3uiACGwwACgkQFlMNXpIPXGWp |
| 70 | TACbBS+Up3RpfYVfd63c1cDdlru13pQAn3NQy/SN858MkxN+zym86UBgOad2 |
| 71 | =CMiZ |
| 72 | -----END PGP PUBLIC KEY BLOCK----- |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 73 | |
| 74 | Conley Owens <[email protected]> |
| 75 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 76 | Version: GnuPG v1.4.11 (GNU/Linux) |
| 77 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 78 | mQENBFHRvc8BCADFg45Xx/y6QDC+T7Y/gGc7vx0ww7qfOwIKlAZ9xG3qKunMxo+S |
| 79 | hPCnzEl3cq+6I1Ww/ndop/HB3N3toPXRCoN8Vs4/Hc7by+SnaLFnacrm+tV5/OgT |
| 80 | V37Lzt8lhay1Kl+YfpFwHYYpIEBLFV9knyfRXS/428W2qhdzYfvB15/AasRmwmor |
| 81 | py4NIzSs8UD/SPr1ihqNCdZM76+MQyN5HMYXW/ALZXUFG0pwluHFA7hrfPG74i8C |
| 82 | zMiP7qvMWIl/r/jtzHioH1dRKgbod+LZsrDJ8mBaqsZaDmNJMhss9g76XvfMyLra |
| 83 | 9DI9/iFuBpGzeqBv0hwOGQspLRrEoyTeR6n1ABEBAAG0H0NvbmxleSBPd2VucyA8 |
| 84 | Y2NvM0BhbmRyb2lkLmNvbT6JATgEEwECACIFAlHRvc8CGwMGCwkIBwMC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ZqX+1 |
| 100 | dzQZt3e13W0rVBb/bUgx9iSLoeWP3aq/k+/GRGOR+S6F6BBSl0SQ2EF2+dIywb1x |
| 101 | JuinEP+AwLAUZ1Bsx9ISC0Agpk2VeHXPL3FGhroEmoMvBzO0kTFGyoeT7PR/BfKv |
| 102 | +H/g3HsL2LOB9uoIm8/5p2TTU5ttYCXMHhQZ81AY |
| 103 | =AUp4 |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 104 | -----END PGP PUBLIC KEY BLOCK----- |
[email protected] | 538283f | 2013-08-13 21:37:50 | [diff] [blame] | 105 | |
| 106 | Stefan Zager <[email protected]> |
| 107 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 108 | Version: GnuPG v1.4.11 (GNU/Linux) |
| 109 | |
| 110 | mQINBFIJOcgBEADwZIq4GRGoO1RJFKlrtVK501cwT5H+Acbizc9N5RxTkFmqxDjb |
| 111 | 9ApUaPW6S1b8+nrzE9P1Ri5erfzipuStfaZ/Wl3mP1JjKulibddmgnPOEbAJ673k |
| 112 | Vj85RUO4rt2oZAHnZN3D3gFJzVY8JVlZ47Enj9fTqzcW78FVsPCpIT9P2LpTLWeE |
| 113 | jX9Cjxeimy6VvyJstIcDLYhlpUN5UWen79L4LFAkHf3luLuU4W3p9NriqUsy5UG2 |
| 114 | 8vO6QdhKrCr5wsjDFFeVnpMtjlSeZJAWH+XhFFibMX1xP5R9BTuJfzw3kOVKvcE0 |
| 115 | e9ClxgoulepXPv2xnDkqO3pG2gQVzl8LA+Aol8/IXfa7KP5FBkxK/g1cDuDtXRk4 |
| 116 | YLpLaLYeeKEhhOHLpsKYkK2DXTIcN+56UnTLGolummpZnCM8UUSZxQgbkFgk4YJL |
| 117 | Elip0hgLZzqEl5h9vjmnQp89AZIHKcgNmzn+szLTOR9x24joaLyQ534x8OSC8lmu |
| 118 | tJv2tQjDOVGWVwvY4gOTpyxCWMwur6WOiMk/TPWdiVRFWAGrAHwf0/CTBEqNhosh |
| 119 | sVXfPeMADBA0PorDbJ6kwcOkLUTGf8CT7OG1R9TuKPEmSjK7BYu/pT4DXitaRCiv |
| 120 | uPVlwbVFpLFr0/jwaKJVMLUjL5MaYwzjJqI2c4RdROZhpMhkn4LvCMmFSQARAQAB |
| 121 | tCJTdGVmYW4gWmFnZXIgPHN6YWdlckBjaHJvbWl1bS5vcmc+iQI4BBMBAgAiBQJS |
| 122 | CTnIAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRDcuoHPGCdZNU0UD/9y |
| 123 | 0zwwOJH2UGPAzZ0YVzr7p0HtKedoxuFvPkdQxlBIaUOueMzFRmNQu3GI9irAu3MQ |
| 124 | Jkip8/gi7dnLVmJyS/zWARBaRGwSVd1++87XDjw8n7l181p7394X0Agq/heri599 |
| 125 | YheHXkxXKVMPqByWNEPHu4eDbxeJTaDIjcKC2pzKQkm6HbWgW4wA9gCh1TRki8FP |
| 126 | LMv1Fu/dr13STCR9P2evsTRZ+ZSJhTSboHNHeEAJGiGZQAsN94oht7647lYj+AyR |
| 127 | ThzyHDMXXiDr8jPJIkyRilY+y82bCOatOfPoCkce3VI+LRUGJ19hJY01m4RRneIE |
| 128 | 55l7fXR3zggcsONjV5b+oLcGQPGgX9w64BJ7khT7Wb9+kuyrdJBIBzJsaACFEbri |
| 129 | pPi02FS/HahYpLC3J66REAeNyofgVXau6WQsHrHMGsBTL9aAr0nrCrkF4Nyyc2Jd |
| 130 | do6nYuljuUhORqbEECmmBM2eBtkL6Ac92D6WMBIwBOC5tCNHO2YFIvi8Y8EuE8sc |
| 131 | 1zB5U5Ai4SIu2icRAhzAhCRaUq02cMWuELKH6Vuh9nzgEefFWty6vPbKEyZLu19D |
| 132 | B80aqP1cTN88FjtKQ/eTF29TUB6AefUeBS17e2e3WUMy4nc8tduuOFYfiHP40ScP |
| 133 | wOoatwfzpiTIPGbocUEPL+pS0O/Xy8SINxFMCud3zA== |
| 134 | =Vd2S |
| 135 | -----END PGP PUBLIC KEY BLOCK----- |
[email protected] | 33c182b | 2014-09-08 17:50:45 | [diff] [blame] | 136 | |
| 137 | David James <[email protected]> |
| 138 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 139 | Version: GnuPG v1 |
| 140 | |
| 141 | mQINBFQKWWsBEACjAxD8xLqNVFX/qOAKFW7R63J3KkkXQKyH5KmSWZnmdfTg4AeR |
| 142 | h9sAUls16nHiOFp/MRLFFhax8dm33zfED+zHpISFUkMq2Q3UyP6Z6eSpJyYriEF1 |
| 143 | hP7PpwksEnh+hoQ36fhsY1vaQRgTCO8XkFVcChb1CoKUl104PornVlZ378RBUUnK |
| 144 | FAPhRSTEJtK1QXv6JtQXFzEQbX3jgxsKvpw/Zg7V3FnaMRhHw84YvCAbWz9ayTov |
| 145 | SBOIczOscD9T/F3NbSlgFwWlQ7JeixdOsCMaYh7gYcXqdq2jluHuKQlTGmGlFwGm |
| 146 | 5TOh6NwvVUV68JZfer2CGMQv4JImQfousy9V+KGddTBfjYkwtmG9oTkSWBLuO91/ |
| 147 | q+TFdHkzNxivPcC+iluJkzrJHcS6aUg8vkLZfT2wrGZUBFH7GsZiKht2env1HyVZ |
| 148 | 64md/auhee4ED3V0mtWSWYyjriAQUIE0LHVHP1zyEf5gVwDZyuE2HlFZr1eFJWiH |
| 149 | jcxQnGi7IpxF2//NCTvO2dc3eTi4f1EexOyomu9AWk/iIDCgCpkU38XlWgVrvmM1 |
| 150 | Mw5pDm691L1Xn3v3yMRZZUCottUpUEnz5qAa0eQHWBU4PpXUCaWElwwuT+3Lcx1U |
| 151 | Rdq74UPNb+hBGzrID/KmeU0NxGmhzRIwl+LKdCvnM2v4AvRHIjQPBqC5fQARAQAB |
| 152 | tCNEYXZpZCBKYW1lcyA8ZGF2aWRqYW1lc0Bnb29nbGUuY29tPokCOAQTAQIAIgUC |
| 153 | VApZawIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQSlDprdejN6zH5A// |
| 154 | XRAytpjxTIHTtMWp1c7vpi1BMiKF0XRSa8iizbVgZIk6i/jftK8tverRvOzQhUEK |
| 155 | mwP6WDoX9SbkvxxQd+AxaRmDCQSf7h/fFMB+q9WycH5Mj+N4mc7iivsf1RdZzlmF |
| 156 | l1wcJoGVsOTFrccca/ZcXjMhWCfpVNDGn29nFtHKddSORhQgy8x0NVf/8NXOF1OL |
| 157 | Le4cZKBwSokPJEL1Ta4bNQPkzY251CSjH9feHCE1ac16/wh1qhkozl8/QbIVFVTA |
| 158 | wk1m6q7raj22+2HifrM/w5YkNXYcEL/SfusbCo/rtax75fG0lT9whB6OXuzk0CTu |
| 159 | zsdBHaYGKCQ+gcalpxqQ/o+xFo0HNI6duCo1zBFAkSX20HZcU5IWr8C2psTuB5zo |
| 160 | 3vPT89GMNlFVhG4JBvuSHcgJFBoTEALugDX1xiRqidjhKPpDMl3Gcezakg2ethQM |
| 161 | 9zwmdlsbh/stcLh9U6eNOqxrjMgmrMRjDocaMu0gFXoGbEMeVVJWrLGgF51k6Q9w |
| 162 | U3/pvyws6OukV4y3Sr57ACbeQ1am0pCKir2HXB2jmShJfINSyPqhluMz/q1CbYEE |
| 163 | R7oWoVIL70qhCr4hdJ4yVtqajkUr5jk+IV9L2pny6zt3+3e/132O6yzQ/1NJ1vj9 |
| 164 | hxSNFwdO/JWdqgYtvsFvWQGdKp+RwYBJBp1XIOBA+5W5Ag0EVApZawEQAMC/t6AF |
| 165 | 1eU2wZcLQaahmv+1yaQCV7VfwH8/Lh1AZbMNEITnp97gJ/6SlQqL0fDfjX8DKGE+ |
| 166 | U23o3fKMJr8tIxJqLVzPROomeG+9zhtq5hI3qu53zhR3bCqQpYPQcIHRHxtttYkP |
| 167 | p+rdTZlYX09TaSsTITNs0/1dCHEgyDS48ujOSmA0fr9eGyxv/2Chr0sDEkSaerJp |
| 168 | teDKmUdkKoF9SCR7ntfrSFP3eXYFFy+wb+IQjVVHAdTgossXKPtNxzdEKQQHJESJ |
| 169 | e1jD5BlOpvysOcbDJaRCq7TE2o3Grwy8Um1/Fv+n9naIAN6bZNSrPtiH2G7nX4l6 |
| 170 | 126so5sBhJTSGbIV/fb93PZCIfzfJCA4pinYPJH46zn2Ih3AF9mi4eguBK9/oGBe |
| 171 | 03LsNBsfoEI81rRuAl5NeFNa+YXf3w7olF2qbwZXcGmRBteUBBvfonW64nk8w+Ui |
| 172 | x14gzHJXH6l9jsIavA1AMtFulmh6eEf8hsDUzq8s0Yg9PphVmknxPVW44EttOwCi |
| 173 | OnlVelRSbABcCNNTv1vOC8ubvt191YRNwAgGMRmXfeEFce76ckVJei/tiENycMXl |
| 174 | Ff3+km6WmswsDmKxz+DfNtf5SXM24EifO2Q6uX9pbg+AcIWI9Sc2WAfmqCooTU8g |
| 175 | H2Ua0dskiAi9qq4DPYrwPO+OzAT10nn/TqmDABEBAAGJAh8EGAECAAkFAlQKWWsC |
| 176 | GwwACgkQSlDprdejN6wHURAAncjYkIkSseO8lldTVu0qJi2vetc2Q6bR8Lw1hTAT |
| 177 | TB2LcbFheTu6Q/sxDSC5slovFSgyDp8wNkDf88+fxV38LC00IeWz7a9EGPzLzA+D |
| 178 | fNFdctnxXZGaYB3cQ17TkKFj4AMqbzKPkt4xYWU/WdSWPPd4feFJVjg7l8BIxafF |
| 179 | 58ZYbWN3DwAgKE9DDZ9praTNC/2ytWh21a2j8LR4GlYERW1pMGrMt37IGvZqbU6W |
| 180 | a7HWaB7f0eXg5M5GTr7KP6TTGwY/500cI4fDme6bih/jXDS4vV53b1HHgvzQFXw/ |
| 181 | XURueobmqsbQQzDGsqPzkYJM4fxXu0TWNhW8CieZMMypPq3uSgvN3jTu2JB9NAEz |
| 182 | 21Pso0NzKm6wxhMzPA6KWILmR2KQn/t51NTE6u0+8e9RmQeg9Ce+IpPzPLsGuNca |
| 183 | u+r4LcB98D8jIUXz9PPbIHiDLJjMWOG8olZz1zcHpt86b+bf8c9TxFAE8p3G/jpQ |
| 184 | qanHjtbgNmkz+JpvJ9CTEEo69tkcbmOaCNwCWQL+Doqqi7tWMYUbAw0Rk+lOSu/N |
| 185 | 4cAccd41XU/GmIs9zKkbORWubhfFndc7AXnPUU2otjqMQq0f+QCQrHPdyARf2QCm |
| 186 | j8zzwdwkRpt3SSvqzh3+L3Zq8xeb2M6u/QLz4aLFTR7yQJed0DJFUcISii9ccJr/ |
| 187 | IM4= |
| 188 | =6VNc |
| 189 | -----END PGP PUBLIC KEY BLOCK----- |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 190 | |
| 191 | Mike Frysinger <[email protected]> |
| 192 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 193 | Version: GnuPG v1 |
| 194 | |
| 195 | mQINBFfYaqQBEAC5M4xbKTZX0MJ9IITJRBjh78/b4z6BcSjJ02nBoyvVuH3yzWJS |
| 196 | O51T0rAsbg/issl4U79tImzBHU4iqgZLO1anRXlVWaGP5N/DBcU6j5tNqNr6EFY/ |
| 197 | 0MHgVrFUKzXWx6NsRnh2xCj7YL4u4DGqP/JO4rY698QNfeKW+u/PpK0FZjmDU1J4 |
| 198 | K9Uh3hrfsCKyaL9tJ0sJUl9uc+Yf2FENSCXaL670ymwC7KqJf/nShA4QjDSQlVZq |
| 199 | Q8t27m0KY2URQi4dsIHYcYQ43VEvQ2ZAjfJkTzOqAk3NcSvRl3Chc8f+o0OiFaVR |
| 200 | xOr3/Pph7nvfIoK0yr3rgBvR/be6aP7wyd6+E/KFszbhrpyZfZsFRGn9LyUqVm3T |
| 201 | iO4GyWs+DvOUmDigMzcKYUHgQ8tk4T89wJd7yXMOlfZKWwMhN59ZuBlvXtogxrSz |
| 202 | jD6Em1TYsvqGaK8fKRRdoP32DsXVt+mbECpNrZqFtsrcOhQhMvLjcC8kRongWD0U |
| 203 | gfohjqPnDGL15ztyedP3iGgb/7usPFI+k3cHgiMfvmqD2F+iJ7h69sSb2nn8dx8P |
| 204 | EiycPnOc8mBDiTAH8eq6T6P29G9mqYr/wyC3Xj66+1WOApXmQS2I6P4qKOdnJdNF |
| 205 | UTI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p7iLrv5v7NMsnw5Wg7d/niTAfqPkyQupm/IJB8DfU7Hw18R5ex/zwFVm6dBTY/O |
| 221 | t/Z6vHAULePZbQFsncXrdyvQaKOmds4alxyzSDraJT74ddM55kmbylkLxVm2DsgF |
| 222 | hEaMs7C+MdOYfTRlVDNJV3oOqqDHsfUM7q92vfJ2Y85jFvf/h/ypg1I4UORC0mUL |
| 223 | 1Wy8CsZzTokmFfaz+97olVQl6/JpxmBqX0GtvU8INWJ2PNLo8E6UMA8OUIzEhSlp |
| 224 | pwBTNUTf9u1wyfm5VUXpW541oVmqAWWHTZh2HVeBW6F1YtsqItZXcNjt6HTL1Qou |
| 225 | Dn+mK+tV0egPsus0tnfmps6ONhvxfZtkRWsJkQ0EDh8SbIEnBd8zolXXJnDSTpjL |
| 226 | n9Sf5d2wH3L2SI53vhMouSB1UmhPhwNq7sFeTvYJ1juqmVdN+eQj5OxSvhOceAE8 |
| 227 | cT2GjBrfkP6Gcw8fPESLqJLx6jpyPrHS/TK1GNCnGZihDsZRNIcfpS9T1LoFKuHn |
| 228 | eRZoYnWnFIZVjD9OLmRq3I2RcktWHFpAjWE3naSybXhfL++mp04PQyV2CUFVF6zY |
| 229 | 2nPL/TtwSF0WmReP2qO7gsuEhR0BuPaXEC3dihTpMZ4hkbe3F+aJ7VEEU9dKDUM= |
| 230 | =i88c |
| 231 | -----END PGP PUBLIC KEY BLOCK----- |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 232 | """ |
| 233 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 234 | GIT = 'git' # our git command |
| 235 | MIN_GIT_VERSION = (1, 7, 2) # minimum supported git version |
| 236 | repodir = '.repo' # name of repo's private directory |
| 237 | S_repo = 'repo' # special repo repository |
| 238 | S_manifests = 'manifests' # special manifest repository |
| 239 | REPO_MAIN = S_repo + '/main.py' # main script |
| 240 | MIN_PYTHON_VERSION = (2, 6) # minimum supported python version |
| 241 | GITC_CONFIG_FILE = '/gitc/.config' |
| 242 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 243 | |
| 244 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 245 | import errno |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 246 | import optparse |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 247 | import re |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 248 | import shutil |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 249 | import stat |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 250 | import subprocess |
| 251 | import sys |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 252 | |
| 253 | if sys.version_info[0] == 3: |
| 254 | import urllib.request |
| 255 | import urllib.error |
| 256 | else: |
| 257 | import imp |
| 258 | import urllib2 |
| 259 | urllib = imp.new_module('urllib') |
| 260 | urllib.request = urllib2 |
| 261 | urllib.error = urllib2 |
| 262 | |
| 263 | |
| 264 | def _print(*objects, **kwargs): |
| 265 | sep = kwargs.get('sep', ' ') |
| 266 | end = kwargs.get('end', '\n') |
| 267 | out = kwargs.get('file', sys.stdout) |
| 268 | out.write(sep.join(objects) + end) |
| 269 | |
| 270 | |
| 271 | # Python version check |
| 272 | ver = sys.version_info |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 273 | if (ver[0], ver[1]) < MIN_PYTHON_VERSION: |
| 274 | _print('error: Python version %s unsupported.\n' |
| 275 | 'Please use Python 2.6 - 2.7 instead.' |
| 276 | % sys.version.split(' ')[0], file=sys.stderr) |
| 277 | sys.exit(1) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 278 | |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 279 | home_dot_repo = os.path.expanduser('~/.repoconfig') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 280 | gpg_dir = os.path.join(home_dot_repo, 'gnupg') |
| 281 | |
| 282 | extra_args = [] |
| 283 | init_optparse = optparse.OptionParser(usage="repo init -u url [options]") |
| 284 | |
| 285 | # Logging |
| 286 | group = init_optparse.add_option_group('Logging options') |
| 287 | group.add_option('-q', '--quiet', |
| 288 | dest="quiet", action="store_true", default=False, |
| 289 | help="be quiet") |
| 290 | |
| 291 | # Manifest |
| 292 | group = init_optparse.add_option_group('Manifest options') |
| 293 | group.add_option('-u', '--manifest-url', |
| 294 | dest='manifest_url', |
| 295 | help='manifest repository location', metavar='URL') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 296 | group.add_option('-b', '--manifest-branch', |
| 297 | dest='manifest_branch', |
| 298 | help='manifest branch or revision', metavar='REVISION') |
| 299 | group.add_option('-m', '--manifest-name', |
| 300 | dest='manifest_name', |
[email protected] | b25b69b | 2011-06-16 17:41:05 | [diff] [blame] | 301 | help='initial manifest file', metavar='NAME.xml') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 302 | group.add_option('--mirror', |
| 303 | dest='mirror', action='store_true', |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 304 | help='create a replica of the remote repositories ' |
| 305 | 'rather than a client working directory') |
[email protected] | 2c64b71 | 2011-01-11 22:57:47 | [diff] [blame] | 306 | group.add_option('--reference', |
| 307 | dest='reference', |
| 308 | help='location of mirror directory', metavar='DIR') |
[email protected] | b25b69b | 2011-06-16 17:41:05 | [diff] [blame] | 309 | group.add_option('--depth', type='int', default=None, |
| 310 | dest='depth', |
| 311 | help='create a shallow clone with given depth; see git clone') |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 312 | group.add_option('--archive', |
| 313 | dest='archive', action='store_true', |
| 314 | help='checkout an archive instead of a git repository for ' |
| 315 | 'each project. See git archive.') |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 316 | group.add_option('-g', '--groups', |
| 317 | dest='groups', default='default', |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 318 | help='restrict manifest projects to ones with specified ' |
| 319 | 'group(s) [default|all|G1,G2,G3|G4,-G5,-G6]', |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 320 | metavar='GROUP') |
| 321 | group.add_option('-p', '--platform', |
| 322 | dest='platform', default="auto", |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 323 | help='restrict manifest projects to ones with a specified ' |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 324 | 'platform group [auto|all|none|linux|darwin|...]', |
| 325 | metavar='PLATFORM') |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 326 | group.add_option('--no-clone-bundle', |
| 327 | dest='no_clone_bundle', action='store_true', |
| 328 | help='disable use of /clone.bundle on HTTP/HTTPS') |
[email protected] | b25b69b | 2011-06-16 17:41:05 | [diff] [blame] | 329 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 330 | |
| 331 | # Tool |
| 332 | group = init_optparse.add_option_group('repo Version options') |
| 333 | group.add_option('--repo-url', |
| 334 | dest='repo_url', |
| 335 | help='repo repository location', metavar='URL') |
| 336 | group.add_option('--repo-branch', |
| 337 | dest='repo_branch', |
| 338 | help='repo branch or revision', metavar='REVISION') |
| 339 | group.add_option('--no-repo-verify', |
| 340 | dest='no_repo_verify', action='store_true', |
| 341 | help='do not verify repo source code') |
| 342 | |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 343 | # Other |
| 344 | group = init_optparse.add_option_group('Other options') |
| 345 | group.add_option('--config-name', |
| 346 | dest='config_name', action="store_true", default=False, |
| 347 | help='Always prompt for name/e-mail') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 348 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 349 | |
| 350 | def _GitcInitOptions(init_optparse_arg): |
| 351 | init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]") |
| 352 | g = init_optparse_arg.add_option_group('GITC options') |
| 353 | g.add_option('-f', '--manifest-file', |
| 354 | dest='manifest_file', |
| 355 | help='Optional manifest file to use for this GITC client.') |
| 356 | g.add_option('-c', '--gitc-client', |
| 357 | dest='gitc_client', |
| 358 | help='The name of the gitc_client instance to create or modify.') |
| 359 | |
| 360 | _gitc_manifest_dir = None |
| 361 | |
| 362 | |
| 363 | def get_gitc_manifest_dir(): |
| 364 | global _gitc_manifest_dir |
| 365 | if _gitc_manifest_dir is None: |
| 366 | _gitc_manifest_dir = '' |
| 367 | try: |
| 368 | with open(GITC_CONFIG_FILE, 'r') as gitc_config: |
| 369 | for line in gitc_config: |
| 370 | match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line) |
| 371 | if match: |
| 372 | _gitc_manifest_dir = match.group('gitc_manifest_dir') |
| 373 | except IOError: |
| 374 | pass |
| 375 | return _gitc_manifest_dir |
| 376 | |
| 377 | |
| 378 | def gitc_parse_clientdir(gitc_fs_path): |
| 379 | """Parse a path in the GITC FS and return its client name. |
| 380 | |
| 381 | @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR. |
| 382 | |
| 383 | @returns: The GITC client name |
| 384 | """ |
| 385 | if gitc_fs_path == GITC_FS_ROOT_DIR: |
| 386 | return None |
| 387 | if not gitc_fs_path.startswith(GITC_FS_ROOT_DIR): |
| 388 | manifest_dir = get_gitc_manifest_dir() |
| 389 | if manifest_dir == '': |
| 390 | return None |
| 391 | if manifest_dir[-1] != '/': |
| 392 | manifest_dir += '/' |
| 393 | if gitc_fs_path == manifest_dir: |
| 394 | return None |
| 395 | if not gitc_fs_path.startswith(manifest_dir): |
| 396 | return None |
| 397 | return gitc_fs_path.split(manifest_dir)[1].split('/')[0] |
| 398 | return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0] |
| 399 | |
| 400 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 401 | class CloneFailure(Exception): |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 402 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 403 | """Indicate the remote clone of repo itself failed. |
| 404 | """ |
| 405 | |
| 406 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 407 | def _Init(args, gitc_init=False): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 408 | """Installs repo by cloning it over the network. |
| 409 | """ |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 410 | if gitc_init: |
| 411 | _GitcInitOptions(init_optparse) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 412 | opt, args = init_optparse.parse_args(args) |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 413 | if args: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 414 | init_optparse.print_usage() |
| 415 | sys.exit(1) |
| 416 | |
| 417 | url = opt.repo_url |
| 418 | if not url: |
| 419 | url = REPO_URL |
| 420 | extra_args.append('--repo-url=%s' % url) |
| 421 | |
| 422 | branch = opt.repo_branch |
| 423 | if not branch: |
| 424 | branch = REPO_REV |
| 425 | extra_args.append('--repo-branch=%s' % branch) |
| 426 | |
| 427 | if branch.startswith('refs/heads/'): |
| 428 | branch = branch[len('refs/heads/'):] |
| 429 | if branch.startswith('refs/'): |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 430 | _print("fatal: invalid branch name '%s'" % branch, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 431 | raise CloneFailure() |
| 432 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 433 | try: |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 434 | if gitc_init: |
| 435 | gitc_manifest_dir = get_gitc_manifest_dir() |
| 436 | if not gitc_manifest_dir: |
| 437 | _print('fatal: GITC filesystem is not available. Exiting...', |
| 438 | file=sys.stderr) |
| 439 | sys.exit(1) |
| 440 | gitc_client = opt.gitc_client |
| 441 | if not gitc_client: |
| 442 | gitc_client = gitc_parse_clientdir(os.getcwd()) |
| 443 | if not gitc_client: |
| 444 | _print('fatal: GITC client (-c) is required.', file=sys.stderr) |
| 445 | sys.exit(1) |
| 446 | client_dir = os.path.join(gitc_manifest_dir, gitc_client) |
| 447 | if not os.path.exists(client_dir): |
| 448 | os.makedirs(client_dir) |
| 449 | os.chdir(client_dir) |
| 450 | if os.path.exists(repodir): |
| 451 | # This GITC Client has already initialized repo so continue. |
| 452 | return |
| 453 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 454 | os.mkdir(repodir) |
| 455 | except OSError as e: |
| 456 | if e.errno != errno.EEXIST: |
| 457 | _print('fatal: cannot make %s directory: %s' |
| 458 | % (repodir, e.strerror), file=sys.stderr) |
| 459 | # Don't raise CloneFailure; that would delete the |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 460 | # name. Instead exit immediately. |
| 461 | # |
| 462 | sys.exit(1) |
| 463 | |
| 464 | _CheckGitVersion() |
| 465 | try: |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 466 | if NeedSetupGnuPG(): |
| 467 | can_verify = SetupGnuPG(opt.quiet) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 468 | else: |
| 469 | can_verify = True |
| 470 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 471 | dst = os.path.abspath(os.path.join(repodir, S_repo)) |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 472 | _Clone(url, dst, opt.quiet, not opt.no_clone_bundle) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 473 | |
| 474 | if can_verify and not opt.no_repo_verify: |
| 475 | rev = _Verify(dst, branch, opt.quiet) |
| 476 | else: |
| 477 | rev = 'refs/remotes/origin/%s^0' % branch |
| 478 | |
| 479 | _Checkout(dst, branch, rev, opt.quiet) |
| 480 | except CloneFailure: |
| 481 | if opt.quiet: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 482 | _print('fatal: repo init failed; run without --quiet to see why', |
| 483 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 484 | raise |
| 485 | |
| 486 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 487 | def ParseGitVersion(ver_str): |
| 488 | if not ver_str.startswith('git version '): |
| 489 | return None |
| 490 | |
| 491 | num_ver_str = ver_str[len('git version '):].strip().split('-')[0] |
| 492 | to_tuple = [] |
| 493 | for num_str in num_ver_str.split('.')[:3]: |
| 494 | if num_str.isdigit(): |
| 495 | to_tuple.append(int(num_str)) |
| 496 | else: |
| 497 | to_tuple.append(0) |
| 498 | return tuple(to_tuple) |
| 499 | |
| 500 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 501 | def _CheckGitVersion(): |
| 502 | cmd = [GIT, '--version'] |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 503 | try: |
| 504 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 505 | except OSError as e: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 506 | _print(file=sys.stderr) |
| 507 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 508 | _print('fatal: %s' % e, file=sys.stderr) |
| 509 | _print(file=sys.stderr) |
| 510 | _print('Please make sure %s is installed and in your path.' % GIT, |
| 511 | file=sys.stderr) |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 512 | raise CloneFailure() |
| 513 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 514 | ver_str = proc.stdout.read().strip() |
| 515 | proc.stdout.close() |
| 516 | proc.wait() |
| 517 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 518 | ver_act = ParseGitVersion(ver_str) |
| 519 | if ver_act is None: |
| 520 | _print('error: "%s" unsupported' % ver_str, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 521 | raise CloneFailure() |
| 522 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 523 | if ver_act < MIN_GIT_VERSION: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 524 | need = '.'.join(map(str, MIN_GIT_VERSION)) |
| 525 | _print('fatal: git %s or later required' % need, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 526 | raise CloneFailure() |
| 527 | |
| 528 | |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 529 | def NeedSetupGnuPG(): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 530 | if not os.path.isdir(home_dot_repo): |
| 531 | return True |
| 532 | |
| 533 | kv = os.path.join(home_dot_repo, 'keyring-version') |
| 534 | if not os.path.exists(kv): |
| 535 | return True |
| 536 | |
| 537 | kv = open(kv).read() |
| 538 | if not kv: |
| 539 | return True |
| 540 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 541 | kv = tuple(map(int, kv.split('.'))) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 542 | if kv < KEYRING_VERSION: |
| 543 | return True |
| 544 | return False |
| 545 | |
| 546 | |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 547 | def SetupGnuPG(quiet): |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 548 | try: |
| 549 | os.mkdir(home_dot_repo) |
| 550 | except OSError as e: |
| 551 | if e.errno != errno.EEXIST: |
| 552 | _print('fatal: cannot make %s directory: %s' |
| 553 | % (home_dot_repo, e.strerror), file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 554 | sys.exit(1) |
| 555 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 556 | try: |
| 557 | os.mkdir(gpg_dir, stat.S_IRWXU) |
| 558 | except OSError as e: |
| 559 | if e.errno != errno.EEXIST: |
| 560 | _print('fatal: cannot make %s directory: %s' % (gpg_dir, e.strerror), |
| 561 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 562 | sys.exit(1) |
| 563 | |
[email protected] | 2c64b71 | 2011-01-11 22:57:47 | [diff] [blame] | 564 | env = os.environ.copy() |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 565 | try: |
| 566 | env['GNUPGHOME'] = gpg_dir |
| 567 | except UnicodeEncodeError: |
| 568 | env['GNUPGHOME'] = gpg_dir.encode() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 569 | |
| 570 | cmd = ['gpg', '--import'] |
| 571 | try: |
| 572 | proc = subprocess.Popen(cmd, |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 573 | env=env, |
| 574 | stdin=subprocess.PIPE) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 575 | except OSError as e: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 576 | if not quiet: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 577 | _print('warning: gpg (GnuPG) is not available.', file=sys.stderr) |
| 578 | _print('warning: Installing it is strongly encouraged.', file=sys.stderr) |
| 579 | _print(file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 580 | return False |
| 581 | |
| 582 | proc.stdin.write(MAINTAINER_KEYS) |
| 583 | proc.stdin.close() |
| 584 | |
| 585 | if proc.wait() != 0: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 586 | _print('fatal: registering repo maintainer keys failed', file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 587 | sys.exit(1) |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 588 | _print() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 589 | |
| 590 | fd = open(os.path.join(home_dot_repo, 'keyring-version'), 'w') |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 591 | fd.write('.'.join(map(str, KEYRING_VERSION)) + '\n') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 592 | fd.close() |
| 593 | return True |
| 594 | |
| 595 | |
| 596 | def _SetConfig(local, name, value): |
| 597 | """Set a git configuration option to the specified value. |
| 598 | """ |
| 599 | cmd = [GIT, 'config', name, value] |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 600 | if subprocess.Popen(cmd, cwd=local).wait() != 0: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 601 | raise CloneFailure() |
| 602 | |
| 603 | |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 604 | def _InitHttp(): |
| 605 | handlers = [] |
| 606 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 607 | mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 608 | try: |
| 609 | import netrc |
| 610 | n = netrc.netrc() |
| 611 | for host in n.hosts: |
| 612 | p = n.hosts[host] |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 613 | mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2]) |
[email protected] | 79245bf | 2012-06-14 21:22:01 | [diff] [blame] | 614 | mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2]) |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 615 | except: # pylint: disable=bare-except |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 616 | pass |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 617 | handlers.append(urllib.request.HTTPBasicAuthHandler(mgr)) |
| 618 | handlers.append(urllib.request.HTTPDigestAuthHandler(mgr)) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 619 | |
| 620 | if 'http_proxy' in os.environ: |
| 621 | url = os.environ['http_proxy'] |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 622 | handlers.append(urllib.request.ProxyHandler({'http': url, 'https': url})) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 623 | if 'REPO_CURL_VERBOSE' in os.environ: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 624 | handlers.append(urllib.request.HTTPHandler(debuglevel=1)) |
| 625 | handlers.append(urllib.request.HTTPSHandler(debuglevel=1)) |
| 626 | urllib.request.install_opener(urllib.request.build_opener(*handlers)) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 627 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 628 | |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 629 | def _Fetch(url, local, src, quiet): |
| 630 | if not quiet: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 631 | _print('Get %s' % url, file=sys.stderr) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 632 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 633 | cmd = [GIT, 'fetch'] |
| 634 | if quiet: |
| 635 | cmd.append('--quiet') |
| 636 | err = subprocess.PIPE |
| 637 | else: |
| 638 | err = None |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 639 | cmd.append(src) |
| 640 | cmd.append('+refs/heads/*:refs/remotes/origin/*') |
| 641 | cmd.append('refs/tags/*:refs/tags/*') |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 642 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 643 | proc = subprocess.Popen(cmd, cwd=local, stderr=err) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 644 | if err: |
| 645 | proc.stderr.read() |
| 646 | proc.stderr.close() |
| 647 | if proc.wait() != 0: |
| 648 | raise CloneFailure() |
| 649 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 650 | |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 651 | def _DownloadBundle(url, local, quiet): |
| 652 | if not url.endswith('/'): |
| 653 | url += '/' |
| 654 | url += 'clone.bundle' |
| 655 | |
| 656 | proc = subprocess.Popen( |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 657 | [GIT, 'config', '--get-regexp', 'url.*.insteadof'], |
| 658 | cwd=local, |
| 659 | stdout=subprocess.PIPE) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 660 | for line in proc.stdout: |
| 661 | m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line) |
| 662 | if m: |
| 663 | new_url = m.group(1) |
| 664 | old_url = m.group(2) |
| 665 | if url.startswith(old_url): |
| 666 | url = new_url + url[len(old_url):] |
| 667 | break |
| 668 | proc.stdout.close() |
| 669 | proc.wait() |
| 670 | |
| 671 | if not url.startswith('http:') and not url.startswith('https:'): |
| 672 | return False |
| 673 | |
| 674 | dest = open(os.path.join(local, '.git', 'clone.bundle'), 'w+b') |
| 675 | try: |
| 676 | try: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 677 | r = urllib.request.urlopen(url) |
| 678 | except urllib.error.HTTPError as e: |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 679 | if e.code in [401, 403, 404, 501]: |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 680 | return False |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 681 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 682 | _print('fatal: HTTP error %s' % e.code, file=sys.stderr) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 683 | raise CloneFailure() |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 684 | except urllib.error.URLError as e: |
| 685 | _print('fatal: Cannot get %s' % url, file=sys.stderr) |
| 686 | _print('fatal: error %s' % e.reason, file=sys.stderr) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 687 | raise CloneFailure() |
| 688 | try: |
| 689 | if not quiet: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 690 | _print('Get %s' % url, file=sys.stderr) |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 691 | while True: |
| 692 | buf = r.read(8192) |
| 693 | if buf == '': |
| 694 | return True |
| 695 | dest.write(buf) |
| 696 | finally: |
| 697 | r.close() |
| 698 | finally: |
| 699 | dest.close() |
| 700 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 701 | |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 702 | def _ImportBundle(local): |
| 703 | path = os.path.join(local, '.git', 'clone.bundle') |
| 704 | try: |
| 705 | _Fetch(local, local, path, True) |
| 706 | finally: |
| 707 | os.remove(path) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 708 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 709 | |
| 710 | def _Clone(url, local, quiet, clone_bundle): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 711 | """Clones a git repository to a new subdirectory of repodir |
| 712 | """ |
| 713 | try: |
| 714 | os.mkdir(local) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 715 | except OSError as e: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 716 | _print('fatal: cannot make %s directory: %s' % (local, e.strerror), |
| 717 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 718 | raise CloneFailure() |
| 719 | |
| 720 | cmd = [GIT, 'init', '--quiet'] |
| 721 | try: |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 722 | proc = subprocess.Popen(cmd, cwd=local) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 723 | except OSError as e: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 724 | _print(file=sys.stderr) |
| 725 | _print("fatal: '%s' is not available" % GIT, file=sys.stderr) |
| 726 | _print('fatal: %s' % e, file=sys.stderr) |
| 727 | _print(file=sys.stderr) |
| 728 | _print('Please make sure %s is installed and in your path.' % GIT, |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 729 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 730 | raise CloneFailure() |
| 731 | if proc.wait() != 0: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 732 | _print('fatal: could not create %s' % local, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 733 | raise CloneFailure() |
| 734 | |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 735 | _InitHttp() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 736 | _SetConfig(local, 'remote.origin.url', url) |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 737 | _SetConfig(local, |
| 738 | 'remote.origin.fetch', |
| 739 | '+refs/heads/*:refs/remotes/origin/*') |
| 740 | if clone_bundle and _DownloadBundle(url, local, quiet): |
[email protected] | ad39056 | 2011-11-12 00:37:07 | [diff] [blame] | 741 | _ImportBundle(local) |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 742 | _Fetch(url, local, 'origin', quiet) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 743 | |
| 744 | |
| 745 | def _Verify(cwd, branch, quiet): |
| 746 | """Verify the branch has been signed by a tag. |
| 747 | """ |
| 748 | cmd = [GIT, 'describe', 'origin/%s' % branch] |
| 749 | proc = subprocess.Popen(cmd, |
| 750 | stdout=subprocess.PIPE, |
| 751 | stderr=subprocess.PIPE, |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 752 | cwd=cwd) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 753 | cur = proc.stdout.read().strip() |
| 754 | proc.stdout.close() |
| 755 | |
| 756 | proc.stderr.read() |
| 757 | proc.stderr.close() |
| 758 | |
| 759 | if proc.wait() != 0 or not cur: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 760 | _print(file=sys.stderr) |
| 761 | _print("fatal: branch '%s' has not been signed" % branch, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 762 | raise CloneFailure() |
| 763 | |
| 764 | m = re.compile(r'^(.*)-[0-9]{1,}-g[0-9a-f]{1,}$').match(cur) |
| 765 | if m: |
| 766 | cur = m.group(1) |
| 767 | if not quiet: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 768 | _print(file=sys.stderr) |
| 769 | _print("info: Ignoring branch '%s'; using tagged release '%s'" |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 770 | % (branch, cur), file=sys.stderr) |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 771 | _print(file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 772 | |
[email protected] | 2c64b71 | 2011-01-11 22:57:47 | [diff] [blame] | 773 | env = os.environ.copy() |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 774 | try: |
| 775 | env['GNUPGHOME'] = gpg_dir |
| 776 | except UnicodeEncodeError: |
| 777 | env['GNUPGHOME'] = gpg_dir.encode() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 778 | |
| 779 | cmd = [GIT, 'tag', '-v', cur] |
| 780 | proc = subprocess.Popen(cmd, |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 781 | stdout=subprocess.PIPE, |
| 782 | stderr=subprocess.PIPE, |
| 783 | cwd=cwd, |
| 784 | env=env) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 785 | out = proc.stdout.read() |
| 786 | proc.stdout.close() |
| 787 | |
| 788 | err = proc.stderr.read() |
| 789 | proc.stderr.close() |
| 790 | |
| 791 | if proc.wait() != 0: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 792 | _print(file=sys.stderr) |
| 793 | _print(out, file=sys.stderr) |
| 794 | _print(err, file=sys.stderr) |
| 795 | _print(file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 796 | raise CloneFailure() |
| 797 | return '%s^0' % cur |
| 798 | |
| 799 | |
| 800 | def _Checkout(cwd, branch, rev, quiet): |
| 801 | """Checkout an upstream branch into the repository and track it. |
| 802 | """ |
| 803 | cmd = [GIT, 'update-ref', 'refs/heads/default', rev] |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 804 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 805 | raise CloneFailure() |
| 806 | |
| 807 | _SetConfig(cwd, 'branch.default.remote', 'origin') |
| 808 | _SetConfig(cwd, 'branch.default.merge', 'refs/heads/%s' % branch) |
| 809 | |
| 810 | cmd = [GIT, 'symbolic-ref', 'HEAD', 'refs/heads/default'] |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 811 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 812 | raise CloneFailure() |
| 813 | |
| 814 | cmd = [GIT, 'read-tree', '--reset', '-u'] |
| 815 | if not quiet: |
| 816 | cmd.append('-v') |
| 817 | cmd.append('HEAD') |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 818 | if subprocess.Popen(cmd, cwd=cwd).wait() != 0: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 819 | raise CloneFailure() |
| 820 | |
| 821 | |
| 822 | def _FindRepo(): |
| 823 | """Look for a repo installation, starting at the current directory. |
| 824 | """ |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 825 | curdir = os.getcwd() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 826 | repo = None |
| 827 | |
[email protected] | 2c64b71 | 2011-01-11 22:57:47 | [diff] [blame] | 828 | olddir = None |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 829 | while curdir != '/' \ |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 830 | and curdir != olddir \ |
| 831 | and not repo: |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 832 | repo = os.path.join(curdir, repodir, REPO_MAIN) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 833 | if not os.path.isfile(repo): |
| 834 | repo = None |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 835 | olddir = curdir |
| 836 | curdir = os.path.dirname(curdir) |
| 837 | return (repo, os.path.join(curdir, repodir)) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 838 | |
| 839 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 840 | class _Options(object): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 841 | help = False |
| 842 | |
| 843 | |
| 844 | def _ParseArguments(args): |
| 845 | cmd = None |
| 846 | opt = _Options() |
| 847 | arg = [] |
| 848 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 849 | for i in range(len(args)): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 850 | a = args[i] |
| 851 | if a == '-h' or a == '--help': |
| 852 | opt.help = True |
| 853 | |
| 854 | elif not a.startswith('-'): |
| 855 | cmd = a |
| 856 | arg = args[i + 1:] |
| 857 | break |
| 858 | return cmd, opt, arg |
| 859 | |
| 860 | |
| 861 | def _Usage(): |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 862 | gitc_usage = "" |
| 863 | if get_gitc_manifest_dir(): |
| 864 | gitc_usage = " gitc-init Initialize a GITC Client.\n" |
| 865 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 866 | _print( |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 867 | """usage: repo COMMAND [ARGS] |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 868 | |
| 869 | repo is not yet installed. Use "repo init" to install it here. |
| 870 | |
| 871 | The most commonly used repo commands are: |
| 872 | |
| 873 | init Install repo in the current working directory |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 874 | """ + gitc_usage + |
| 875 | """ help Display detailed help on a command |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 876 | |
| 877 | For access to the full online help, install repo ("repo init"). |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 878 | """, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 879 | sys.exit(1) |
| 880 | |
| 881 | |
| 882 | def _Help(args): |
| 883 | if args: |
| 884 | if args[0] == 'init': |
| 885 | init_optparse.print_help() |
[email protected] | 2c64b71 | 2011-01-11 22:57:47 | [diff] [blame] | 886 | sys.exit(0) |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 887 | elif args[0] == 'gitc-init': |
| 888 | _GitcInitOptions(init_optparse) |
| 889 | init_optparse.print_help() |
| 890 | sys.exit(0) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 891 | else: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 892 | _print("error: '%s' is not a bootstrap command.\n" |
| 893 | ' For access to online help, install repo ("repo init").' |
| 894 | % args[0], file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 895 | else: |
| 896 | _Usage() |
| 897 | sys.exit(1) |
| 898 | |
| 899 | |
| 900 | def _NotInstalled(): |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 901 | _print('error: repo is not installed. Use "repo init" to install it here.', |
| 902 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 903 | sys.exit(1) |
| 904 | |
| 905 | |
| 906 | def _NoCommands(cmd): |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 907 | _print("""error: command '%s' requires repo to be installed first. |
| 908 | Use "repo init" to install it here.""" % cmd, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 909 | sys.exit(1) |
| 910 | |
| 911 | |
| 912 | def _RunSelf(wrapper_path): |
| 913 | my_dir = os.path.dirname(wrapper_path) |
| 914 | my_main = os.path.join(my_dir, 'main.py') |
| 915 | my_git = os.path.join(my_dir, '.git') |
| 916 | |
| 917 | if os.path.isfile(my_main) and os.path.isdir(my_git): |
| 918 | for name in ['git_config.py', |
| 919 | 'project.py', |
| 920 | 'subcmds']: |
| 921 | if not os.path.exists(os.path.join(my_dir, name)): |
| 922 | return None, None |
| 923 | return my_main, my_git |
| 924 | return None, None |
| 925 | |
| 926 | |
| 927 | def _SetDefaultsTo(gitdir): |
| 928 | global REPO_URL |
| 929 | global REPO_REV |
| 930 | |
| 931 | REPO_URL = gitdir |
| 932 | proc = subprocess.Popen([GIT, |
| 933 | '--git-dir=%s' % gitdir, |
| 934 | 'symbolic-ref', |
| 935 | 'HEAD'], |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 936 | stdout=subprocess.PIPE, |
| 937 | stderr=subprocess.PIPE) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 938 | REPO_REV = proc.stdout.read().strip() |
| 939 | proc.stdout.close() |
| 940 | |
| 941 | proc.stderr.read() |
| 942 | proc.stderr.close() |
| 943 | |
| 944 | if proc.wait() != 0: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 945 | _print('fatal: %s has no current branch' % gitdir, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 946 | sys.exit(1) |
| 947 | |
| 948 | |
| 949 | def main(orig_args): |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 950 | cmd, opt, args = _ParseArguments(orig_args) |
| 951 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 952 | repo_main, rel_repo_dir = None, None |
| 953 | # Don't use the local repo copy, make sure to switch to the gitc client first. |
| 954 | if cmd != 'gitc-init': |
| 955 | repo_main, rel_repo_dir = _FindRepo() |
| 956 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 957 | wrapper_path = os.path.abspath(__file__) |
| 958 | my_main, my_git = _RunSelf(wrapper_path) |
| 959 | |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 960 | cwd = os.getcwd() |
| 961 | if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()): |
| 962 | _print('error: repo cannot be used in the GITC local manifest directory.' |
| 963 | '\nIf you want to work on this GITC client please rerun this ' |
| 964 | 'command from the corresponding client under /gitc/', |
| 965 | file=sys.stderr) |
| 966 | sys.exit(1) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 967 | if not repo_main: |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 968 | if opt.help: |
| 969 | _Usage() |
| 970 | if cmd == 'help': |
| 971 | _Help(args) |
| 972 | if not cmd: |
| 973 | _NotInstalled() |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 974 | if cmd == 'init' or cmd == 'gitc-init': |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 975 | if my_git: |
| 976 | _SetDefaultsTo(my_git) |
| 977 | try: |
vapier | ae39f56 | 2016-10-11 02:08:17 | [diff] [blame] | 978 | _Init(args, gitc_init=(cmd == 'gitc-init')) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 979 | except CloneFailure: |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 980 | shutil.rmtree(os.path.join(repodir, S_repo), ignore_errors=True) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 981 | sys.exit(1) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 982 | repo_main, rel_repo_dir = _FindRepo() |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 983 | else: |
| 984 | _NoCommands(cmd) |
| 985 | |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 986 | if my_main: |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 987 | repo_main = my_main |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 988 | |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 989 | ver_str = '.'.join(map(str, VERSION)) |
| 990 | me = [sys.executable, repo_main, |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 991 | '--repo-dir=%s' % rel_repo_dir, |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 992 | '--wrapper-version=%s' % ver_str, |
| 993 | '--wrapper-path=%s' % wrapper_path, |
| 994 | '--'] |
| 995 | me.extend(orig_args) |
| 996 | me.extend(extra_args) |
| 997 | try: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 998 | os.execv(sys.executable, me) |
[email protected] | 8db6c88 | 2012-12-25 17:02:37 | [diff] [blame] | 999 | except OSError as e: |
[email protected] | 3bdfbeb | 2014-02-06 04:52:54 | [diff] [blame] | 1000 | _print("fatal: unable to start %s" % repo_main, file=sys.stderr) |
| 1001 | _print("fatal: %s" % e, file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 1002 | sys.exit(148) |
| 1003 | |
| 1004 | |
| 1005 | if __name__ == '__main__': |
vapier | 7475196 | 2016-09-14 23:08:34 | [diff] [blame] | 1006 | if ver[0] == 3: |
| 1007 | _print('warning: Python 3 support is currently experimental. YMMV.\n' |
| 1008 | 'Please use Python 2.6 - 2.7 instead.', |
| 1009 | file=sys.stderr) |
[email protected] | 38b04f8 | 2010-07-13 23:03:34 | [diff] [blame] | 1010 | main(sys.argv[1:]) |