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