Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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