Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

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