Clone of official tools
synch.py@35:da9c89f8be7d, 2017-02-15 (annotated)
- Committer:
- The Other Jimmy
- Date:
- Wed Feb 15 13:53:18 2017 -0600
- Revision:
- 35:da9c89f8be7d
- Parent:
- 31:8ea194f6145b
Update tools to mbed-os 5.3.5
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 |
The Other Jimmy |
35:da9c89f8be7d | 24 | from os import walk, remove, makedirs, getcwd, rmdir, listdir |
The Other Jimmy |
35:da9c89f8be7d | 25 | from os.path import join, abspath, dirname, relpath, exists, isfile, normpath, isdir |
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 | 13:ab47a20b66f0 | 35 | from tools.paths import * |
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 |
The Other Jimmy |
35:da9c89f8be7d | 49 | OFFICIAL_CODE = {"mbed-dev" : ["cmsis", "drivers", "hal", "platform", "targets", "mbed.h"]} |
screamer | 0:66f3b5499f7f | 50 | |
screamer | 0:66f3b5499f7f | 51 | |
screamer | 0:66f3b5499f7f | 52 | # A list of regular expressions that will be checked against each directory |
screamer | 0:66f3b5499f7f | 53 | # name and skipped if they match. |
screamer | 0:66f3b5499f7f | 54 | IGNORE_DIRS = ( |
screamer | 0:66f3b5499f7f | 55 | ) |
screamer | 0:66f3b5499f7f | 56 | |
screamer | 0:66f3b5499f7f | 57 | IGNORE_FILES = ( |
screamer | 0:66f3b5499f7f | 58 | 'COPYING', |
screamer | 0:66f3b5499f7f | 59 | '\.md', |
screamer | 0:66f3b5499f7f | 60 | "\.lib", |
screamer | 0:66f3b5499f7f | 61 | "\.bld" |
screamer | 0:66f3b5499f7f | 62 | ) |
screamer | 0:66f3b5499f7f | 63 | |
screamer | 0:66f3b5499f7f | 64 | def ignore_path(name, reg_exps): |
screamer | 0:66f3b5499f7f | 65 | for r in reg_exps: |
screamer | 0:66f3b5499f7f | 66 | if re.search(r, name): |
screamer | 0:66f3b5499f7f | 67 | return True |
screamer | 0:66f3b5499f7f | 68 | return False |
screamer | 0:66f3b5499f7f | 69 | |
screamer | 0:66f3b5499f7f | 70 | class MbedRepository: |
screamer | 0:66f3b5499f7f | 71 | @staticmethod |
screamer | 0:66f3b5499f7f | 72 | def run_and_print(command, cwd): |
screamer | 17:04753e1e329d | 73 | stdout, _, _ = run_cmd(command, work_dir=cwd, redirect=True) |
screamer | 0:66f3b5499f7f | 74 | print(stdout) |
screamer | 0:66f3b5499f7f | 75 | |
The Other Jimmy |
35:da9c89f8be7d | 76 | def __init__(self, name): |
screamer | 0:66f3b5499f7f | 77 | self.name = name |
screamer | 0:66f3b5499f7f | 78 | self.path = join(MBED_ORG_PATH, name) |
The Other Jimmy |
35:da9c89f8be7d | 79 | self.url = "http://" + MBED_URL + "/users/" + MBED_ORG_USER + "/code/%s/" |
The Other Jimmy |
35:da9c89f8be7d | 80 | |
screamer | 0:66f3b5499f7f | 81 | if not exists(self.path): |
screamer | 0:66f3b5499f7f | 82 | # Checkout code |
screamer | 0:66f3b5499f7f | 83 | if not exists(MBED_ORG_PATH): |
screamer | 0:66f3b5499f7f | 84 | makedirs(MBED_ORG_PATH) |
screamer | 0:66f3b5499f7f | 85 | |
screamer | 0:66f3b5499f7f | 86 | self.run_and_print(['hg', 'clone', self.url % name], cwd=MBED_ORG_PATH) |
screamer | 0:66f3b5499f7f | 87 | |
screamer | 0:66f3b5499f7f | 88 | else: |
screamer | 0:66f3b5499f7f | 89 | # Update |
screamer | 0:66f3b5499f7f | 90 | self.run_and_print(['hg', 'pull'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 91 | self.run_and_print(['hg', 'update'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 92 | |
screamer | 0:66f3b5499f7f | 93 | def publish(self): |
screamer | 0:66f3b5499f7f | 94 | # The maintainer has to evaluate the changes first and explicitly accept them |
screamer | 0:66f3b5499f7f | 95 | self.run_and_print(['hg', 'addremove'], cwd=self.path) |
screamer | 17:04753e1e329d | 96 | stdout, _, _ = run_cmd(['hg', 'status'], work_dir=self.path) |
screamer | 0:66f3b5499f7f | 97 | if stdout == '': |
screamer | 0:66f3b5499f7f | 98 | print "No changes" |
screamer | 0:66f3b5499f7f | 99 | return False |
screamer | 0:66f3b5499f7f | 100 | print stdout |
screamer | 0:66f3b5499f7f | 101 | if quiet: |
screamer | 0:66f3b5499f7f | 102 | commit = 'Y' |
screamer | 0:66f3b5499f7f | 103 | else: |
screamer | 0:66f3b5499f7f | 104 | 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 | 105 | if commit == 'Y': |
screamer | 0:66f3b5499f7f | 106 | args = ['hg', 'commit', '-u', MBED_ORG_USER] |
The Other Jimmy |
35:da9c89f8be7d | 107 | |
The Other Jimmy |
35:da9c89f8be7d | 108 | |
The Other Jimmy |
35:da9c89f8be7d | 109 | # NOTE commit_msg should always come from the relevant mbed 2 release text |
screamer | 0:66f3b5499f7f | 110 | if commit_msg: |
screamer | 0:66f3b5499f7f | 111 | args = args + ['-m', commit_msg] |
screamer | 0:66f3b5499f7f | 112 | self.run_and_print(args, cwd=self.path) |
screamer | 0:66f3b5499f7f | 113 | if push_remote: |
screamer | 0:66f3b5499f7f | 114 | self.run_and_print(['hg', 'push'], cwd=self.path) |
screamer | 0:66f3b5499f7f | 115 | return True |
screamer | 0:66f3b5499f7f | 116 | |
screamer | 0:66f3b5499f7f | 117 | # Check if a file is a text file or a binary file |
screamer | 0:66f3b5499f7f | 118 | # Taken from http://code.activestate.com/recipes/173220/ |
screamer | 0:66f3b5499f7f | 119 | text_characters = "".join(map(chr, range(32, 127)) + list("\n\r\t\b")) |
screamer | 0:66f3b5499f7f | 120 | _null_trans = string.maketrans("", "") |
screamer | 0:66f3b5499f7f | 121 | def is_text_file(filename): |
screamer | 0:66f3b5499f7f | 122 | block_size = 1024 |
screamer | 0:66f3b5499f7f | 123 | def istext(s): |
screamer | 0:66f3b5499f7f | 124 | if "\0" in s: |
screamer | 0:66f3b5499f7f | 125 | return 0 |
screamer | 0:66f3b5499f7f | 126 | |
screamer | 0:66f3b5499f7f | 127 | if not s: # Empty files are considered text |
screamer | 0:66f3b5499f7f | 128 | return 1 |
screamer | 0:66f3b5499f7f | 129 | |
screamer | 0:66f3b5499f7f | 130 | # Get the non-text characters (maps a character to itself then |
screamer | 0:66f3b5499f7f | 131 | # use the 'remove' option to get rid of the text characters.) |
screamer | 0:66f3b5499f7f | 132 | t = s.translate(_null_trans, text_characters) |
screamer | 0:66f3b5499f7f | 133 | |
screamer | 0:66f3b5499f7f | 134 | # If more than 30% non-text characters, then |
screamer | 0:66f3b5499f7f | 135 | # this is considered a binary file |
screamer | 0:66f3b5499f7f | 136 | if float(len(t))/len(s) > 0.30: |
screamer | 0:66f3b5499f7f | 137 | return 0 |
screamer | 0:66f3b5499f7f | 138 | return 1 |
screamer | 0:66f3b5499f7f | 139 | with open(filename) as f: |
screamer | 0:66f3b5499f7f | 140 | res = istext(f.read(block_size)) |
screamer | 0:66f3b5499f7f | 141 | return res |
screamer | 0:66f3b5499f7f | 142 | |
screamer | 0:66f3b5499f7f | 143 | # Return the line ending type for the given file ('cr' or 'crlf') |
screamer | 0:66f3b5499f7f | 144 | def get_line_endings(f): |
screamer | 0:66f3b5499f7f | 145 | examine_size = 1024 |
screamer | 0:66f3b5499f7f | 146 | try: |
screamer | 0:66f3b5499f7f | 147 | tf = open(f, "rb") |
screamer | 0:66f3b5499f7f | 148 | lines, ncrlf = tf.readlines(examine_size), 0 |
screamer | 0:66f3b5499f7f | 149 | tf.close() |
screamer | 0:66f3b5499f7f | 150 | for l in lines: |
screamer | 0:66f3b5499f7f | 151 | if l.endswith("\r\n"): |
screamer | 0:66f3b5499f7f | 152 | ncrlf = ncrlf + 1 |
screamer | 0:66f3b5499f7f | 153 | return 'crlf' if ncrlf > len(lines) >> 1 else 'cr' |
screamer | 0:66f3b5499f7f | 154 | except: |
screamer | 0:66f3b5499f7f | 155 | return 'cr' |
screamer | 0:66f3b5499f7f | 156 | |
screamer | 0:66f3b5499f7f | 157 | # Copy file to destination, but preserve destination line endings if possible |
screamer | 0:66f3b5499f7f | 158 | # This prevents very annoying issues with huge diffs that appear because of |
screamer | 0:66f3b5499f7f | 159 | # differences in line endings |
screamer | 0:66f3b5499f7f | 160 | def copy_with_line_endings(sdk_file, repo_file): |
screamer | 0:66f3b5499f7f | 161 | if not isfile(repo_file): |
screamer | 0:66f3b5499f7f | 162 | copyfile(sdk_file, repo_file) |
screamer | 0:66f3b5499f7f | 163 | return |
screamer | 0:66f3b5499f7f | 164 | is_text = is_text_file(repo_file) |
screamer | 0:66f3b5499f7f | 165 | if is_text: |
screamer | 0:66f3b5499f7f | 166 | sdk_le = get_line_endings(sdk_file) |
screamer | 0:66f3b5499f7f | 167 | repo_le = get_line_endings(repo_file) |
screamer | 0:66f3b5499f7f | 168 | if not is_text or sdk_le == repo_le: |
screamer | 0:66f3b5499f7f | 169 | copyfile(sdk_file, repo_file) |
screamer | 0:66f3b5499f7f | 170 | else: |
screamer | 0:66f3b5499f7f | 171 | print "Converting line endings in '%s' to '%s'" % (abspath(repo_file), repo_le) |
screamer | 0:66f3b5499f7f | 172 | f = open(sdk_file, "rb") |
screamer | 0:66f3b5499f7f | 173 | data = f.read() |
screamer | 0:66f3b5499f7f | 174 | f.close() |
screamer | 0:66f3b5499f7f | 175 | f = open(repo_file, "wb") |
screamer | 0:66f3b5499f7f | 176 | data = data.replace("\r\n", "\n") if repo_le == 'cr' else data.replace('\n','\r\n') |
screamer | 0:66f3b5499f7f | 177 | f.write(data) |
screamer | 0:66f3b5499f7f | 178 | f.close() |
screamer | 0:66f3b5499f7f | 179 | |
screamer | 0:66f3b5499f7f | 180 | def visit_files(path, visit): |
The Other Jimmy |
35:da9c89f8be7d | 181 | for root, dirs, files in walk(path): |
screamer | 0:66f3b5499f7f | 182 | # Ignore hidden directories |
screamer | 0:66f3b5499f7f | 183 | for d in copy(dirs): |
screamer | 0:66f3b5499f7f | 184 | full = join(root, d) |
screamer | 0:66f3b5499f7f | 185 | if d.startswith('.'): |
screamer | 0:66f3b5499f7f | 186 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 187 | if ignore_path(full, IGNORE_DIRS): |
screamer | 0:66f3b5499f7f | 188 | print "Skipping '%s'" % full |
screamer | 0:66f3b5499f7f | 189 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 190 | |
screamer | 0:66f3b5499f7f | 191 | for file in files: |
screamer | 0:66f3b5499f7f | 192 | if ignore_path(file, IGNORE_FILES): |
screamer | 0:66f3b5499f7f | 193 | continue |
screamer | 0:66f3b5499f7f | 194 | |
screamer | 0:66f3b5499f7f | 195 | visit(join(root, file)) |
screamer | 0:66f3b5499f7f | 196 | |
The Other Jimmy |
35:da9c89f8be7d | 197 | def visit_dirs(path, visit): |
screamer | 0:66f3b5499f7f | 198 | |
The Other Jimmy |
35:da9c89f8be7d | 199 | for root, dirs, files in walk(path, topdown=False): |
The Other Jimmy |
35:da9c89f8be7d | 200 | for d in dirs: |
The Other Jimmy |
35:da9c89f8be7d | 201 | full = join(root, d) |
The Other Jimmy |
35:da9c89f8be7d | 202 | |
The Other Jimmy |
35:da9c89f8be7d | 203 | # We don't want to remove the .hg directory |
The Other Jimmy |
35:da9c89f8be7d | 204 | if not '.hg' in full: |
The Other Jimmy |
35:da9c89f8be7d | 205 | visit(full) |
The Other Jimmy |
35:da9c89f8be7d | 206 | |
The Other Jimmy |
35:da9c89f8be7d | 207 | |
The Other Jimmy |
35:da9c89f8be7d | 208 | def update_repo(repo_name, sdk_paths, lib=False): |
The Other Jimmy |
35:da9c89f8be7d | 209 | repo = MbedRepository(repo_name) |
The Other Jimmy |
35:da9c89f8be7d | 210 | |
screamer | 0:66f3b5499f7f | 211 | # copy files from mbed SDK to mbed_official repository |
screamer | 0:66f3b5499f7f | 212 | def visit_mbed_sdk(sdk_file): |
screamer | 0:66f3b5499f7f | 213 | |
The Other Jimmy |
35:da9c89f8be7d | 214 | # Source files structure is different for the compiled binary lib |
The Other Jimmy |
35:da9c89f8be7d | 215 | # compared to the mbed-dev sources |
The Other Jimmy |
35:da9c89f8be7d | 216 | if lib: |
The Other Jimmy |
35:da9c89f8be7d | 217 | repo_file = join(repo.path, relpath(sdk_file, sdk_path)) |
The Other Jimmy |
35:da9c89f8be7d | 218 | else: |
The Other Jimmy |
35:da9c89f8be7d | 219 | repo_file = join(repo.path, sdk_file) |
screamer | 0:66f3b5499f7f | 220 | repo_dir = dirname(repo_file) |
screamer | 0:66f3b5499f7f | 221 | if not exists(repo_dir): |
The Other Jimmy |
35:da9c89f8be7d | 222 | print("CREATING: %s" % repo_dir) |
screamer | 0:66f3b5499f7f | 223 | makedirs(repo_dir) |
screamer | 0:66f3b5499f7f | 224 | |
screamer | 0:66f3b5499f7f | 225 | copy_with_line_endings(sdk_file, repo_file) |
The Other Jimmy |
35:da9c89f8be7d | 226 | |
The Other Jimmy |
35:da9c89f8be7d | 227 | # Go through each path specified in the mbed structure |
screamer | 0:66f3b5499f7f | 228 | for sdk_path in sdk_paths: |
The Other Jimmy |
35:da9c89f8be7d | 229 | |
The Other Jimmy |
35:da9c89f8be7d | 230 | if isfile(sdk_path): |
The Other Jimmy |
35:da9c89f8be7d | 231 | # Single file so just copy directly across |
The Other Jimmy |
35:da9c89f8be7d | 232 | visit_mbed_sdk(sdk_path) |
The Other Jimmy |
35:da9c89f8be7d | 233 | else: |
The Other Jimmy |
35:da9c89f8be7d | 234 | visit_files(sdk_path, visit_mbed_sdk) |
The Other Jimmy |
35:da9c89f8be7d | 235 | |
The Other Jimmy |
35:da9c89f8be7d | 236 | def sdk_remove(repo_path): |
The Other Jimmy |
35:da9c89f8be7d | 237 | |
The Other Jimmy |
35:da9c89f8be7d | 238 | print("REMOVING: %s" % repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 239 | |
The Other Jimmy |
35:da9c89f8be7d | 240 | # Check if this is an empty directory or a file before determining how to |
The Other Jimmy |
35:da9c89f8be7d | 241 | # delete it. As this function should only be called with a directory list |
The Other Jimmy |
35:da9c89f8be7d | 242 | # after being called with a file list, the directory should automatically |
The Other Jimmy |
35:da9c89f8be7d | 243 | # be either valid or empty . |
The Other Jimmy |
35:da9c89f8be7d | 244 | if isfile(repo_path): |
The Other Jimmy |
35:da9c89f8be7d | 245 | remove(repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 246 | elif isdir(repo_path) and not listdir(repo_path): |
The Other Jimmy |
35:da9c89f8be7d | 247 | rmdir(repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 248 | else: |
The Other Jimmy |
35:da9c89f8be7d | 249 | print("ERROR: %s is not empty, please remove manually." % repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 250 | print listdir(repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 251 | exit(1) |
screamer | 0:66f3b5499f7f | 252 | |
screamer | 0:66f3b5499f7f | 253 | # remove repository files that do not exist in the mbed SDK |
The Other Jimmy |
35:da9c89f8be7d | 254 | def visit_lib_repo(repo_path): |
screamer | 0:66f3b5499f7f | 255 | for sdk_path in sdk_paths: |
The Other Jimmy |
35:da9c89f8be7d | 256 | sdk_file = join(sdk_path, relpath(repo_path, repo.path)) |
The Other Jimmy |
35:da9c89f8be7d | 257 | if not exists(sdk_file): |
The Other Jimmy |
35:da9c89f8be7d | 258 | sdk_remove(repo_path) |
The Other Jimmy |
35:da9c89f8be7d | 259 | |
The Other Jimmy |
35:da9c89f8be7d | 260 | # remove repository files that do not exist in the mbed SDK source |
The Other Jimmy |
35:da9c89f8be7d | 261 | def visit_repo(repo_path): |
The Other Jimmy |
35:da9c89f8be7d | 262 | |
The Other Jimmy |
35:da9c89f8be7d | 263 | # work out equivalent sdk path from repo file |
The Other Jimmy |
35:da9c89f8be7d | 264 | sdk_path = join(getcwd(), relpath(repo_path, repo.path)) |
The Other Jimmy |
35:da9c89f8be7d | 265 | |
The Other Jimmy |
35:da9c89f8be7d | 266 | if not exists(sdk_path): |
The Other Jimmy |
35:da9c89f8be7d | 267 | sdk_remove(repo_path) |
screamer | 0:66f3b5499f7f | 268 | |
The Other Jimmy |
35:da9c89f8be7d | 269 | # Go through each path specified in the mbed structure |
The Other Jimmy |
35:da9c89f8be7d | 270 | # Check if there are any files in any of those paths that are no longer part of the SDK |
The Other Jimmy |
35:da9c89f8be7d | 271 | |
The Other Jimmy |
35:da9c89f8be7d | 272 | if lib: |
The Other Jimmy |
35:da9c89f8be7d | 273 | visit_files(repo.path, visit_lib_repo) |
The Other Jimmy |
35:da9c89f8be7d | 274 | # Now do the same for directories that may need to be removed. This needs to be done |
The Other Jimmy |
35:da9c89f8be7d | 275 | # bottom up to ensure any lower nested directories can be deleted first |
The Other Jimmy |
35:da9c89f8be7d | 276 | visit_dirs(repo.path, visit_lib_repo) |
The Other Jimmy |
35:da9c89f8be7d | 277 | |
The Other Jimmy |
35:da9c89f8be7d | 278 | else: |
The Other Jimmy |
35:da9c89f8be7d | 279 | visit_files(repo.path, visit_repo) |
The Other Jimmy |
35:da9c89f8be7d | 280 | |
The Other Jimmy |
35:da9c89f8be7d | 281 | # Now do the same for directories that may need to be removed. This needs to be done |
The Other Jimmy |
35:da9c89f8be7d | 282 | # bottom up to ensure any lower nested directories can be deleted first |
The Other Jimmy |
35:da9c89f8be7d | 283 | visit_dirs(repo.path, visit_repo) |
The Other Jimmy |
35:da9c89f8be7d | 284 | |
screamer | 0:66f3b5499f7f | 285 | if repo.publish(): |
screamer | 0:66f3b5499f7f | 286 | changed.append(repo_name) |
screamer | 0:66f3b5499f7f | 287 | |
screamer | 0:66f3b5499f7f | 288 | |
screamer | 0:66f3b5499f7f | 289 | def update_code(repositories): |
The Other Jimmy |
35:da9c89f8be7d | 290 | for repo_name in repositories.keys(): |
The Other Jimmy |
35:da9c89f8be7d | 291 | sdk_dirs = repositories[repo_name] |
screamer | 0:66f3b5499f7f | 292 | print '\n=== Updating "%s" ===' % repo_name |
The Other Jimmy |
35:da9c89f8be7d | 293 | update_repo(repo_name, sdk_dirs) |
screamer | 0:66f3b5499f7f | 294 | |
screamer | 0:66f3b5499f7f | 295 | |
screamer | 0:66f3b5499f7f | 296 | def update_mbed(): |
The Other Jimmy |
35:da9c89f8be7d | 297 | update_repo("mbed", [join(BUILD_DIR, "mbed")], lib=True) |
screamer | 0:66f3b5499f7f | 298 | |
screamer | 0:66f3b5499f7f | 299 | def do_sync(options): |
screamer | 0:66f3b5499f7f | 300 | global push_remote, quiet, commit_msg, changed |
screamer | 0:66f3b5499f7f | 301 | |
screamer | 0:66f3b5499f7f | 302 | push_remote = not options.nopush |
screamer | 0:66f3b5499f7f | 303 | quiet = options.quiet |
screamer | 0:66f3b5499f7f | 304 | commit_msg = options.msg |
The Other Jimmy |
35:da9c89f8be7d | 305 | changed = [] |
screamer | 0:66f3b5499f7f | 306 | |
screamer | 0:66f3b5499f7f | 307 | if options.code: |
screamer | 0:66f3b5499f7f | 308 | update_code(OFFICIAL_CODE) |
screamer | 0:66f3b5499f7f | 309 | |
screamer | 0:66f3b5499f7f | 310 | if options.mbed: |
screamer | 0:66f3b5499f7f | 311 | update_mbed() |
screamer | 0:66f3b5499f7f | 312 | |
screamer | 0:66f3b5499f7f | 313 | if changed: |
screamer | 0:66f3b5499f7f | 314 | print "Repositories with changes:", changed |
screamer | 0:66f3b5499f7f | 315 | |
screamer | 0:66f3b5499f7f | 316 | return changed |
screamer | 0:66f3b5499f7f | 317 | |
screamer | 0:66f3b5499f7f | 318 | if __name__ == '__main__': |
screamer | 0:66f3b5499f7f | 319 | parser = OptionParser() |
screamer | 0:66f3b5499f7f | 320 | |
screamer | 0:66f3b5499f7f | 321 | parser.add_option("-c", "--code", |
screamer | 0:66f3b5499f7f | 322 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 323 | help="Update the mbed_official code") |
screamer | 0:66f3b5499f7f | 324 | |
screamer | 0:66f3b5499f7f | 325 | parser.add_option("-m", "--mbed", |
screamer | 0:66f3b5499f7f | 326 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 327 | help="Release a build of the mbed library") |
screamer | 0:66f3b5499f7f | 328 | |
screamer | 0:66f3b5499f7f | 329 | parser.add_option("-n", "--nopush", |
screamer | 0:66f3b5499f7f | 330 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 331 | help="Commit the changes locally only, don't push them") |
screamer | 0:66f3b5499f7f | 332 | |
screamer | 0:66f3b5499f7f | 333 | parser.add_option("", "--commit_message", |
screamer | 0:66f3b5499f7f | 334 | action="store", type="string", default='', dest='msg', |
screamer | 0:66f3b5499f7f | 335 | help="Commit message to use for all the commits") |
screamer | 0:66f3b5499f7f | 336 | |
screamer | 0:66f3b5499f7f | 337 | parser.add_option("-q", "--quiet", |
screamer | 0:66f3b5499f7f | 338 | action="store_true", default=False, |
screamer | 0:66f3b5499f7f | 339 | help="Don't ask for confirmation before commiting or pushing") |
screamer | 0:66f3b5499f7f | 340 | |
screamer | 0:66f3b5499f7f | 341 | (options, args) = parser.parse_args() |
screamer | 0:66f3b5499f7f | 342 | |
screamer | 0:66f3b5499f7f | 343 | do_sync(options) |
screamer | 0:66f3b5499f7f | 344 |