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