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