Clone of official tools
synch.py@0:66f3b5499f7f, 2016-05-19 (annotated)
- Committer:
- screamer
- Date:
- Thu May 19 19:44:41 2016 +0100
- Revision:
- 0:66f3b5499f7f
- Child:
- 13:ab47a20b66f0
Initial revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:66f3b5499f7f | 1 | """ |
screamer | 0:66f3b5499f7f | 2 | mbed SDK |
screamer | 0:66f3b5499f7f | 3 | Copyright (c) 2011-2013 ARM Limited |
screamer | 0:66f3b5499f7f | 4 | |
screamer | 0:66f3b5499f7f | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
screamer | 0:66f3b5499f7f | 6 | you may not use this file except in compliance with the License. |
screamer | 0:66f3b5499f7f | 7 | You may obtain a copy of the License at |
screamer | 0:66f3b5499f7f | 8 | |
screamer | 0:66f3b5499f7f | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
screamer | 0:66f3b5499f7f | 10 | |
screamer | 0:66f3b5499f7f | 11 | Unless required by applicable law or agreed to in writing, software |
screamer | 0:66f3b5499f7f | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
screamer | 0:66f3b5499f7f | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
screamer | 0:66f3b5499f7f | 14 | See the License for the specific language governing permissions and |
screamer | 0:66f3b5499f7f | 15 | limitations under the License. |
screamer | 0:66f3b5499f7f | 16 | |
screamer | 0:66f3b5499f7f | 17 | |
screamer | 0:66f3b5499f7f | 18 | One repository to update them all |
screamer | 0:66f3b5499f7f | 19 | On mbed.org the mbed SDK is split up in multiple repositories, this script takes |
screamer | 0:66f3b5499f7f | 20 | care of updating them all. |
screamer | 0:66f3b5499f7f | 21 | """ |
screamer | 0:66f3b5499f7f | 22 | import sys |
screamer | 0:66f3b5499f7f | 23 | from copy import copy |
screamer | 0:66f3b5499f7f | 24 | from os import walk, remove, makedirs |
screamer | 0:66f3b5499f7f | 25 | from os.path import join, abspath, dirname, relpath, exists, isfile |
screamer | 0:66f3b5499f7f | 26 | from shutil import copyfile |
screamer | 0:66f3b5499f7f | 27 | from optparse import OptionParser |
screamer | 0:66f3b5499f7f | 28 | import re |
screamer | 0:66f3b5499f7f | 29 | import string |
screamer | 0:66f3b5499f7f | 30 | |
screamer | 0:66f3b5499f7f | 31 | ROOT = abspath(join(dirname(__file__), "..")) |
screamer | 0:66f3b5499f7f | 32 | sys.path.insert(0, ROOT) |
screamer | 0:66f3b5499f7f | 33 | |
screamer | 0:66f3b5499f7f | 34 | from tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR |
screamer | 0:66f3b5499f7f | 35 | from tools.paths import LIB_DIR |
screamer | 0:66f3b5499f7f | 36 | from tools.utils import run_cmd |
screamer | 0:66f3b5499f7f | 37 | |
screamer | 0:66f3b5499f7f | 38 | MBED_URL = "mbed.org" |
screamer | 0:66f3b5499f7f | 39 | MBED_USER = "mbed_official" |
screamer | 0:66f3b5499f7f | 40 | |
screamer | 0:66f3b5499f7f | 41 | changed = [] |
screamer | 0:66f3b5499f7f | 42 | push_remote = True |
screamer | 0:66f3b5499f7f | 43 | quiet = False |
screamer | 0:66f3b5499f7f | 44 | commit_msg = '' |
screamer | 0:66f3b5499f7f | 45 | |
screamer | 0:66f3b5499f7f | 46 | # Code that does have a mirror in the mbed SDK |
screamer | 0:66f3b5499f7f | 47 | # Tuple data: (repo_name, list_of_code_dirs, [team]) |
screamer | 0:66f3b5499f7f | 48 | # team is optional - if not specified, the code is published under mbed_official |
screamer | 0:66f3b5499f7f | 49 | OFFICIAL_CODE = ( |
screamer | 0:66f3b5499f7f | 50 | ("mbed-dev" , "mbed"), |
screamer | 0:66f3b5499f7f | 51 | ("mbed-rtos", "rtos"), |
screamer | 0:66f3b5499f7f | 52 | ("mbed-dsp" , "dsp"), |
screamer | 0:66f3b5499f7f | 53 | ("mbed-rpc" , "rpc"), |
screamer | 0:66f3b5499f7f | 54 | |
screamer | 0:66f3b5499f7f | 55 | ("lwip" , "net/lwip/lwip"), |
screamer | 0:66f3b5499f7f | 56 | ("lwip-sys", "net/lwip/lwip-sys"), |
screamer | 0:66f3b5499f7f | 57 | ("Socket" , "net/lwip/Socket"), |
screamer | 0:66f3b5499f7f | 58 | |
screamer | 0:66f3b5499f7f | 59 | ("lwip-eth" , "net/eth/lwip-eth"), |
screamer | 0:66f3b5499f7f | 60 | ("EthernetInterface", "net/eth/EthernetInterface"), |
screamer | 0:66f3b5499f7f | 61 | |
screamer | 0:66f3b5499f7f | 62 | ("USBDevice", "USBDevice"), |
screamer | 0:66f3b5499f7f | 63 | ("USBHost" , "USBHost"), |
screamer | 0:66f3b5499f7f | 64 | |
screamer | 0:66f3b5499f7f | 65 | ("CellularModem", "net/cellular/CellularModem"), |
screamer | 0:66f3b5499f7f | 66 | ("CellularUSBModem", "net/cellular/CellularUSBModem"), |
screamer | 0:66f3b5499f7f | 67 | ("UbloxUSBModem", "net/cellular/UbloxUSBModem"), |
screamer | 0:66f3b5499f7f | 68 | ("UbloxModemHTTPClientTest", ["tests/net/cellular/http/common", "tests/net/cellular/http/ubloxusb"]), |
screamer | 0:66f3b5499f7f | 69 | ("UbloxModemSMSTest", ["tests/net/cellular/sms/common", "tests/net/cellular/sms/ubloxusb"]), |
screamer | 0:66f3b5499f7f | 70 | ("FATFileSystem", "fs/fat", "mbed-official"), |
screamer | 0:66f3b5499f7f | 71 | ) |
screamer | 0:66f3b5499f7f | 72 | |
screamer | 0:66f3b5499f7f | 73 | |
screamer | 0:66f3b5499f7f | 74 | # Code that does have dependencies to libraries should point to |
screamer | 0:66f3b5499f7f | 75 | # the latest revision. By default, they point to a specific revision. |
screamer | 0:66f3b5499f7f | 76 | CODE_WITH_DEPENDENCIES = ( |
screamer | 0:66f3b5499f7f | 77 | # Libraries |
screamer | 0:66f3b5499f7f | 78 | "EthernetInterface", |
screamer | 0:66f3b5499f7f | 79 | |
screamer | 0:66f3b5499f7f | 80 | # RTOS Examples |
screamer | 0:66f3b5499f7f | 81 | "rtos_basic", |
screamer | 0:66f3b5499f7f | 82 | "rtos_isr", |
screamer | 0:66f3b5499f7f | 83 | "rtos_mail", |
screamer | 0:66f3b5499f7f | 84 | "rtos_mutex", |
screamer | 0:66f3b5499f7f | 85 | "rtos_queue", |
screamer | 0:66f3b5499f7f | 86 | "rtos_semaphore", |
screamer | 0:66f3b5499f7f | 87 | "rtos_signals", |
screamer | 0:66f3b5499f7f | 88 | "rtos_timer", |
screamer | 0:66f3b5499f7f | 89 | |
screamer | 0:66f3b5499f7f | 90 | # Net Examples |
screamer | 0:66f3b5499f7f | 91 | "TCPEchoClient", |
screamer | 0:66f3b5499f7f | 92 | "TCPEchoServer", |
screamer | 0:66f3b5499f7f | 93 | "TCPSocket_HelloWorld", |
screamer | 0:66f3b5499f7f | 94 | "UDPSocket_HelloWorld", |
screamer | 0:66f3b5499f7f | 95 | "UDPEchoClient", |
screamer | 0:66f3b5499f7f | 96 | "UDPEchoServer", |
screamer | 0:66f3b5499f7f | 97 | "BroadcastReceive", |
screamer | 0:66f3b5499f7f | 98 | "BroadcastSend", |
screamer | 0:66f3b5499f7f | 99 | |
screamer | 0:66f3b5499f7f | 100 | # mbed sources |
screamer | 0:66f3b5499f7f | 101 | "mbed-src-program", |
screamer | 0:66f3b5499f7f | 102 | ) |
screamer | 0:66f3b5499f7f | 103 | |
screamer | 0:66f3b5499f7f | 104 | # A list of regular expressions that will be checked against each directory |
screamer | 0:66f3b5499f7f | 105 | # name and skipped if they match. |
screamer | 0:66f3b5499f7f | 106 | IGNORE_DIRS = ( |
screamer | 0:66f3b5499f7f | 107 | ) |
screamer | 0:66f3b5499f7f | 108 | |
screamer | 0:66f3b5499f7f | 109 | IGNORE_FILES = ( |
screamer | 0:66f3b5499f7f | 110 | 'COPYING', |
screamer | 0:66f3b5499f7f | 111 | '\.md', |
screamer | 0:66f3b5499f7f | 112 | "\.lib", |
screamer | 0:66f3b5499f7f | 113 | "\.bld" |
screamer | 0:66f3b5499f7f | 114 | ) |
screamer | 0:66f3b5499f7f | 115 | |
screamer | 0:66f3b5499f7f | 116 | def ignore_path(name, reg_exps): |
screamer | 0:66f3b5499f7f | 117 | for r in reg_exps: |
screamer | 0:66f3b5499f7f | 118 | if re.search(r, name): |
screamer | 0:66f3b5499f7f | 119 | return True |
screamer | 0:66f3b5499f7f | 120 | return False |
screamer | 0:66f3b5499f7f | 121 | |
screamer | 0:66f3b5499f7f | 122 | class MbedRepository: |
screamer | 0:66f3b5499f7f | 123 | @staticmethod |
screamer | 0:66f3b5499f7f | 124 | def run_and_print(command, cwd): |
screamer | 0:66f3b5499f7f | 125 | stdout, _, _ = run_cmd(command, wd=cwd, redirect=True) |
screamer | 0:66f3b5499f7f | 126 | print(stdout) |
screamer | 0:66f3b5499f7f | 127 | |
screamer | 0:66f3b5499f7f | 128 | def __init__(self, name, team = None): |
screamer | 0:66f3b5499f7f | 129 | self.name = name |
screamer | 0:66f3b5499f7f | 130 | self.path = join(MBED_ORG_PATH, name) |
screamer | 0:66f3b5499f7f | 131 | if team is None: |
screamer | 0:66f3b5499f7f | 132 | self.url = "http://" + MBED_URL + "/users/" + MBED_USER + "/code/%s/" |
screamer | 0:66f3b5499f7f | 133 | else: |
screamer | 0:66f3b5499f7f | 134 | self.url = "http://" + MBED_URL + "/teams/" + team + "/code/%s/" |
screamer | 0:66f3b5499f7f | 135 | if not exists(self.path): |
screamer | 0:66f3b5499f7f | 136 | # Checkout code |
screamer | 0:66f3b5499f7f | 137 | if not exists(MBED_ORG_PATH): |
screamer | 0:66f3b5499f7f | 138 | makedirs(MBED_ORG_PATH) |
screamer | 0:66f3b5499f7f | 139 | |
screamer | 0:66f3b5499f7f | 140 | self.run_and_print(['hg', 'clone', self.url % name], cwd=MBED_ORG_PATH) |
screamer | 0:66f3b5499f7f | 141 | |
screamer | 0:66f3b5499f7f | 142 | else: |
screamer | 0:66f3b5499f7f | 143 | # Update |
screamer | 0:66f3b5499f7f | 144 | self.run_and_print(['hg', 'pull'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 145 | self.run_and_print(['hg', 'update'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 146 | |
screamer | 0:66f3b5499f7f | 147 | def publish(self): |
screamer | 0:66f3b5499f7f | 148 | # The maintainer has to evaluate the changes first and explicitly accept them |
screamer | 0:66f3b5499f7f | 149 | self.run_and_print(['hg', 'addremove'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 150 | stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path) |
screamer | 0:66f3b5499f7f | 151 | if stdout == '': |
screamer | 0:66f3b5499f7f | 152 | print "No changes" |
screamer | 0:66f3b5499f7f | 153 | return False |
screamer | 0:66f3b5499f7f | 154 | print stdout |
screamer | 0:66f3b5499f7f | 155 | if quiet: |
screamer | 0:66f3b5499f7f | 156 | commit = 'Y' |
screamer | 0:66f3b5499f7f | 157 | else: |
screamer | 0:66f3b5499f7f | 158 | commit = raw_input(push_remote and "Do you want to commit and push? Y/N: " or "Do you want to commit? Y/N: ") |
screamer | 0:66f3b5499f7f | 159 | if commit == 'Y': |
screamer | 0:66f3b5499f7f | 160 | args = ['hg', 'commit', '-u', MBED_ORG_USER] |
screamer | 0:66f3b5499f7f | 161 | if commit_msg: |
screamer | 0:66f3b5499f7f | 162 | args = args + ['-m', commit_msg] |
screamer | 0:66f3b5499f7f | 163 | self.run_and_print(args, cwd=self.path) |
screamer | 0:66f3b5499f7f | 164 | if push_remote: |
screamer | 0:66f3b5499f7f | 165 | self.run_and_print(['hg', 'push'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 166 | return True |
screamer | 0:66f3b5499f7f | 167 | |
screamer | 0:66f3b5499f7f | 168 | # Check if a file is a text file or a binary file |
screamer | 0:66f3b5499f7f | 169 | # Taken from http://code.activestate.com/recipes/173220/ |
screamer | 0:66f3b5499f7f | 170 | text_characters = "".join(map(chr, range(32, 127)) + list("\n\r\t\b")) |
screamer | 0:66f3b5499f7f | 171 | _null_trans = string.maketrans("", "") |
screamer | 0:66f3b5499f7f | 172 | def is_text_file(filename): |
screamer | 0:66f3b5499f7f | 173 | block_size = 1024 |
screamer | 0:66f3b5499f7f | 174 | def istext(s): |
screamer | 0:66f3b5499f7f | 175 | if "\0" in s: |
screamer | 0:66f3b5499f7f | 176 | return 0 |
screamer | 0:66f3b5499f7f | 177 | |
screamer | 0:66f3b5499f7f | 178 | if not s: # Empty files are considered text |
screamer | 0:66f3b5499f7f | 179 | return 1 |
screamer | 0:66f3b5499f7f | 180 | |
screamer | 0:66f3b5499f7f | 181 | # Get the non-text characters (maps a character to itself then |
screamer | 0:66f3b5499f7f | 182 | # use the 'remove' option to get rid of the text characters.) |
screamer | 0:66f3b5499f7f | 183 | t = s.translate(_null_trans, text_characters) |
screamer | 0:66f3b5499f7f | 184 | |
screamer | 0:66f3b5499f7f | 185 | # If more than 30% non-text characters, then |
screamer | 0:66f3b5499f7f | 186 | # this is considered a binary file |
screamer | 0:66f3b5499f7f | 187 | if float(len(t))/len(s) > 0.30: |
screamer | 0:66f3b5499f7f | 188 | return 0 |
screamer | 0:66f3b5499f7f | 189 | return 1 |
screamer | 0:66f3b5499f7f | 190 | with open(filename) as f: |
screamer | 0:66f3b5499f7f | 191 | res = istext(f.read(block_size)) |
screamer | 0:66f3b5499f7f | 192 | return res |
screamer | 0:66f3b5499f7f | 193 | |
screamer | 0:66f3b5499f7f | 194 | # Return the line ending type for the given file ('cr' or 'crlf') |
screamer | 0:66f3b5499f7f | 195 | def get_line_endings(f): |
screamer | 0:66f3b5499f7f | 196 | examine_size = 1024 |
screamer | 0:66f3b5499f7f | 197 | try: |
screamer | 0:66f3b5499f7f | 198 | tf = open(f, "rb") |
screamer | 0:66f3b5499f7f | 199 | lines, ncrlf = tf.readlines(examine_size), 0 |
screamer | 0:66f3b5499f7f | 200 | tf.close() |
screamer | 0:66f3b5499f7f | 201 | for l in lines: |
screamer | 0:66f3b5499f7f | 202 | if l.endswith("\r\n"): |
screamer | 0:66f3b5499f7f | 203 | ncrlf = ncrlf + 1 |
screamer | 0:66f3b5499f7f | 204 | return 'crlf' if ncrlf > len(lines) >> 1 else 'cr' |
screamer | 0:66f3b5499f7f | 205 | except: |
screamer | 0:66f3b5499f7f | 206 | return 'cr' |
screamer | 0:66f3b5499f7f | 207 | |
screamer | 0:66f3b5499f7f | 208 | # Copy file to destination, but preserve destination line endings if possible |
screamer | 0:66f3b5499f7f | 209 | # This prevents very annoying issues with huge diffs that appear because of |
screamer | 0:66f3b5499f7f | 210 | # differences in line endings |
screamer | 0:66f3b5499f7f | 211 | def copy_with_line_endings(sdk_file, repo_file): |
screamer | 0:66f3b5499f7f | 212 | if not isfile(repo_file): |
screamer | 0:66f3b5499f7f | 213 | copyfile(sdk_file, repo_file) |
screamer | 0:66f3b5499f7f | 214 | return |
screamer | 0:66f3b5499f7f | 215 | is_text = is_text_file(repo_file) |
screamer | 0:66f3b5499f7f | 216 | if is_text: |
screamer | 0:66f3b5499f7f | 217 | sdk_le = get_line_endings(sdk_file) |
screamer | 0:66f3b5499f7f | 218 | repo_le = get_line_endings(repo_file) |
screamer | 0:66f3b5499f7f | 219 | if not is_text or sdk_le == repo_le: |
screamer | 0:66f3b5499f7f | 220 | copyfile(sdk_file, repo_file) |
screamer | 0:66f3b5499f7f | 221 | else: |
screamer | 0:66f3b5499f7f | 222 | print "Converting line endings in '%s' to '%s'" % (abspath(repo_file), repo_le) |
screamer | 0:66f3b5499f7f | 223 | f = open(sdk_file, "rb") |
screamer | 0:66f3b5499f7f | 224 | data = f.read() |
screamer | 0:66f3b5499f7f | 225 | f.close() |
screamer | 0:66f3b5499f7f | 226 | f = open(repo_file, "wb") |
screamer | 0:66f3b5499f7f | 227 | data = data.replace("\r\n", "\n") if repo_le == 'cr' else data.replace('\n','\r\n') |
screamer | 0:66f3b5499f7f | 228 | f.write(data) |
screamer | 0:66f3b5499f7f | 229 | f.close() |
screamer | 0:66f3b5499f7f | 230 | |
screamer | 0:66f3b5499f7f | 231 | def visit_files(path, visit): |
screamer | 0:66f3b5499f7f | 232 | for root, dirs, files in walk(path): |
screamer | 0:66f3b5499f7f | 233 | # Ignore hidden directories |
screamer | 0:66f3b5499f7f | 234 | for d in copy(dirs): |
screamer | 0:66f3b5499f7f | 235 | full = join(root, d) |
screamer | 0:66f3b5499f7f | 236 | if d.startswith('.'): |
screamer | 0:66f3b5499f7f | 237 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 238 | if ignore_path(full, IGNORE_DIRS): |
screamer | 0:66f3b5499f7f | 239 | print "Skipping '%s'" % full |
screamer | 0:66f3b5499f7f | 240 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 241 | |
screamer | 0:66f3b5499f7f | 242 | for file in files: |
screamer | 0:66f3b5499f7f | 243 | if ignore_path(file, IGNORE_FILES): |
screamer | 0:66f3b5499f7f | 244 | continue |
screamer | 0:66f3b5499f7f | 245 | |
screamer | 0:66f3b5499f7f | 246 | visit(join(root, file)) |
screamer | 0:66f3b5499f7f | 247 | |
screamer | 0:66f3b5499f7f | 248 | |
screamer | 0:66f3b5499f7f | 249 | def update_repo(repo_name, sdk_paths, team_name): |
screamer | 0:66f3b5499f7f | 250 | repo = MbedRepository(repo_name, team_name) |
screamer | 0:66f3b5499f7f | 251 | # copy files from mbed SDK to mbed_official repository |
screamer | 0:66f3b5499f7f | 252 | def visit_mbed_sdk(sdk_file): |
screamer | 0:66f3b5499f7f | 253 | repo_file = join(repo.path, relpath(sdk_file, sdk_path)) |
screamer | 0:66f3b5499f7f | 254 | |
screamer | 0:66f3b5499f7f | 255 | repo_dir = dirname(repo_file) |
screamer | 0:66f3b5499f7f | 256 | if not exists(repo_dir): |
screamer | 0:66f3b5499f7f | 257 | makedirs(repo_dir) |
screamer | 0:66f3b5499f7f | 258 | |
screamer | 0:66f3b5499f7f | 259 | copy_with_line_endings(sdk_file, repo_file) |
screamer | 0:66f3b5499f7f | 260 | for sdk_path in sdk_paths: |
screamer | 0:66f3b5499f7f | 261 | visit_files(sdk_path, visit_mbed_sdk) |
screamer | 0:66f3b5499f7f | 262 | |
screamer | 0:66f3b5499f7f | 263 | # remove repository files that do not exist in the mbed SDK |
screamer | 0:66f3b5499f7f | 264 | def visit_repo(repo_file): |
screamer | 0:66f3b5499f7f | 265 | for sdk_path in sdk_paths: |
screamer | 0:66f3b5499f7f | 266 | sdk_file = join(sdk_path, relpath(repo_file, repo.path)) |
screamer | 0:66f3b5499f7f | 267 | if exists(sdk_file): |
screamer | 0:66f3b5499f7f | 268 | break |
screamer | 0:66f3b5499f7f | 269 | else: |
screamer | 0:66f3b5499f7f | 270 | remove(repo_file) |
screamer | 0:66f3b5499f7f | 271 | print "remove: %s" % repo_file |
screamer | 0:66f3b5499f7f | 272 | visit_files(repo.path, visit_repo) |
screamer | 0:66f3b5499f7f | 273 | |
screamer | 0:66f3b5499f7f | 274 | if repo.publish(): |
screamer | 0:66f3b5499f7f | 275 | changed.append(repo_name) |
screamer | 0:66f3b5499f7f | 276 | |
screamer | 0:66f3b5499f7f | 277 | |
screamer | 0:66f3b5499f7f | 278 | def update_code(repositories): |
screamer | 0:66f3b5499f7f | 279 | for r in repositories: |
screamer | 0:66f3b5499f7f | 280 | repo_name, sdk_dir = r[0], r[1] |
screamer | 0:66f3b5499f7f | 281 | team_name = r[2] if len(r) == 3 else None |
screamer | 0:66f3b5499f7f | 282 | print '\n=== Updating "%s" ===' % repo_name |
screamer | 0:66f3b5499f7f | 283 | sdk_dirs = [sdk_dir] if type(sdk_dir) != type([]) else sdk_dir |
screamer | 0:66f3b5499f7f | 284 | sdk_path = [join(LIB_DIR, d) for d in sdk_dirs] |
screamer | 0:66f3b5499f7f | 285 | update_repo(repo_name, sdk_path, team_name) |
screamer | 0:66f3b5499f7f | 286 | |
screamer | 0:66f3b5499f7f | 287 | def update_single_repo(repo): |
screamer | 0:66f3b5499f7f | 288 | repos = [r for r in OFFICIAL_CODE if r[0] == repo] |
screamer | 0:66f3b5499f7f | 289 | if not repos: |
screamer | 0:66f3b5499f7f | 290 | print "Repository '%s' not found" % repo |
screamer | 0:66f3b5499f7f | 291 | else: |
screamer | 0:66f3b5499f7f | 292 | update_code(repos) |
screamer | 0:66f3b5499f7f | 293 | |
screamer | 0:66f3b5499f7f | 294 | def update_dependencies(repositories): |
screamer | 0:66f3b5499f7f | 295 | for repo_name in repositories: |
screamer | 0:66f3b5499f7f | 296 | print '\n=== Updating "%s" ===' % repo_name |
screamer | 0:66f3b5499f7f | 297 | repo = MbedRepository(repo_name) |
screamer | 0:66f3b5499f7f | 298 | |
screamer | 0:66f3b5499f7f | 299 | # point to the latest libraries |
screamer | 0:66f3b5499f7f | 300 | def visit_repo(repo_file): |
screamer | 0:66f3b5499f7f | 301 | with open(repo_file, "r") as f: |
screamer | 0:66f3b5499f7f | 302 | url = f.read() |
screamer | 0:66f3b5499f7f | 303 | with open(repo_file, "w") as f: |
screamer | 0:66f3b5499f7f | 304 | f.write(url[:(url.rindex('/')+1)]) |
screamer | 0:66f3b5499f7f | 305 | visit_files(repo.path, visit_repo, None, MBED_REPO_EXT) |
screamer | 0:66f3b5499f7f | 306 | |
screamer | 0:66f3b5499f7f | 307 | if repo.publish(): |
screamer | 0:66f3b5499f7f | 308 | changed.append(repo_name) |
screamer | 0:66f3b5499f7f | 309 | |
screamer | 0:66f3b5499f7f | 310 | |
screamer | 0:66f3b5499f7f | 311 | def update_mbed(): |
screamer | 0:66f3b5499f7f | 312 | update_repo("mbed", [join(BUILD_DIR, "mbed")], None) |
screamer | 0:66f3b5499f7f | 313 | |
screamer | 0:66f3b5499f7f | 314 | def do_sync(options): |
screamer | 0:66f3b5499f7f | 315 | global push_remote, quiet, commit_msg, changed |
screamer | 0:66f3b5499f7f | 316 | |
screamer | 0:66f3b5499f7f | 317 | push_remote = not options.nopush |
screamer | 0:66f3b5499f7f | 318 | quiet = options.quiet |
screamer | 0:66f3b5499f7f | 319 | commit_msg = options.msg |
screamer | 0:66f3b5499f7f | 320 | chnaged = [] |
screamer | 0:66f3b5499f7f | 321 | |
screamer | 0:66f3b5499f7f | 322 | if options.code: |
screamer | 0:66f3b5499f7f | 323 | update_code(OFFICIAL_CODE) |
screamer | 0:66f3b5499f7f | 324 | |
screamer | 0:66f3b5499f7f | 325 | if options.dependencies: |
screamer | 0:66f3b5499f7f | 326 | update_dependencies(CODE_WITH_DEPENDENCIES) |
screamer | 0:66f3b5499f7f | 327 | |
screamer | 0:66f3b5499f7f | 328 | if options.mbed: |
screamer | 0:66f3b5499f7f | 329 | update_mbed() |
screamer | 0:66f3b5499f7f | 330 | |
screamer | 0:66f3b5499f7f | 331 | if options.repo: |
screamer | 0:66f3b5499f7f | 332 | update_single_repo(options.repo) |
screamer | 0:66f3b5499f7f | 333 | |
screamer | 0:66f3b5499f7f | 334 | if changed: |
screamer | 0:66f3b5499f7f | 335 | print "Repositories with changes:", changed |
screamer | 0:66f3b5499f7f | 336 | |
screamer | 0:66f3b5499f7f | 337 | return changed |
screamer | 0:66f3b5499f7f | 338 | |
screamer | 0:66f3b5499f7f | 339 | if __name__ == '__main__': |
screamer | 0:66f3b5499f7f | 340 | parser = OptionParser() |
screamer | 0:66f3b5499f7f | 341 | |
screamer | 0:66f3b5499f7f | 342 | parser.add_option("-c", "--code", |
screamer | 0:66f3b5499f7f | 343 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 344 | help="Update the mbed_official code") |
screamer | 0:66f3b5499f7f | 345 | |
screamer | 0:66f3b5499f7f | 346 | parser.add_option("-d", "--dependencies", |
screamer | 0:66f3b5499f7f | 347 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 348 | help="Update the mbed_official code dependencies") |
screamer | 0:66f3b5499f7f | 349 | |
screamer | 0:66f3b5499f7f | 350 | parser.add_option("-m", "--mbed", |
screamer | 0:66f3b5499f7f | 351 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 352 | help="Release a build of the mbed library") |
screamer | 0:66f3b5499f7f | 353 | |
screamer | 0:66f3b5499f7f | 354 | parser.add_option("-n", "--nopush", |
screamer | 0:66f3b5499f7f | 355 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 356 | help="Commit the changes locally only, don't push them") |
screamer | 0:66f3b5499f7f | 357 | |
screamer | 0:66f3b5499f7f | 358 | parser.add_option("", "--commit_message", |
screamer | 0:66f3b5499f7f | 359 | action="store", type="string", default='', dest='msg', |
screamer | 0:66f3b5499f7f | 360 | help="Commit message to use for all the commits") |
screamer | 0:66f3b5499f7f | 361 | |
screamer | 0:66f3b5499f7f | 362 | parser.add_option("-r", "--repository", |
screamer | 0:66f3b5499f7f | 363 | action="store", type="string", default='', dest='repo', |
screamer | 0:66f3b5499f7f | 364 | help="Synchronize only the given repository") |
screamer | 0:66f3b5499f7f | 365 | |
screamer | 0:66f3b5499f7f | 366 | parser.add_option("-q", "--quiet", |
screamer | 0:66f3b5499f7f | 367 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 368 | help="Don't ask for confirmation before commiting or pushing") |
screamer | 0:66f3b5499f7f | 369 | |
screamer | 0:66f3b5499f7f | 370 | (options, args) = parser.parse_args() |
screamer | 0:66f3b5499f7f | 371 | |
screamer | 0:66f3b5499f7f | 372 | do_sync(options) |
screamer | 0:66f3b5499f7f | 373 |