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