Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-os
neo.py@35:ffcfa5ace437, 2016-03-30 (annotated)
- Committer:
- Christopher Haster
- Date:
- Wed Mar 30 10:51:38 2016 -0500
- Revision:
- 35:ffcfa5ace437
- Parent:
- 34:8d47baea4754
- Child:
- 36:5f4546dde73b
Inlined checkouts into clone/pull
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
15:a6b1f4e65bf4 | 1 | #!/usr/bin/env python |
Christopher Haster |
15:a6b1f4e65bf4 | 2 | |
Christopher Haster |
15:a6b1f4e65bf4 | 3 | import argparse |
Christopher Haster |
15:a6b1f4e65bf4 | 4 | import sys |
Christopher Haster |
15:a6b1f4e65bf4 | 5 | import re |
Christopher Haster |
15:a6b1f4e65bf4 | 6 | import subprocess |
Christopher Haster |
15:a6b1f4e65bf4 | 7 | import os |
Christopher Haster |
15:a6b1f4e65bf4 | 8 | import contextlib |
Christopher Haster |
15:a6b1f4e65bf4 | 9 | import shutil |
Christopher Haster |
35:ffcfa5ace437 | 10 | from collections import * |
Christopher Haster |
15:a6b1f4e65bf4 | 11 | from itertools import * |
Christopher Haster |
15:a6b1f4e65bf4 | 12 | |
Christopher Haster |
15:a6b1f4e65bf4 | 13 | # Subparser handling |
Christopher Haster |
15:a6b1f4e65bf4 | 14 | parser = argparse.ArgumentParser() |
Christopher Haster |
15:a6b1f4e65bf4 | 15 | subparsers = parser.add_subparsers() |
Christopher Haster |
15:a6b1f4e65bf4 | 16 | |
Christopher Haster |
15:a6b1f4e65bf4 | 17 | def subcommand(name, *args, **kwargs): |
Christopher Haster |
15:a6b1f4e65bf4 | 18 | def subcommand(command): |
Christopher Haster |
15:a6b1f4e65bf4 | 19 | subparser = subparsers.add_parser(name, **kwargs) |
Christopher Haster |
15:a6b1f4e65bf4 | 20 | |
Christopher Haster |
15:a6b1f4e65bf4 | 21 | for arg in args: |
Christopher Haster |
15:a6b1f4e65bf4 | 22 | if arg.endswith('?'): |
Christopher Haster |
15:a6b1f4e65bf4 | 23 | subparser.add_argument(arg.strip('?'), nargs='?') |
Christopher Haster |
15:a6b1f4e65bf4 | 24 | elif arg.endswith('*'): |
Christopher Haster |
15:a6b1f4e65bf4 | 25 | pass |
Christopher Haster |
15:a6b1f4e65bf4 | 26 | else: |
Christopher Haster |
15:a6b1f4e65bf4 | 27 | subparser.add_argument(arg) |
Christopher Haster |
15:a6b1f4e65bf4 | 28 | |
Christopher Haster |
15:a6b1f4e65bf4 | 29 | def thunk(parsed_args): |
Christopher Haster |
15:a6b1f4e65bf4 | 30 | ordered_args = [vars(parsed_args)[arg.strip('?*')] |
Christopher Haster |
15:a6b1f4e65bf4 | 31 | if not arg.endswith('*') else remainder |
Christopher Haster |
15:a6b1f4e65bf4 | 32 | for arg in args] |
Christopher Haster |
15:a6b1f4e65bf4 | 33 | return command(*ordered_args) |
Christopher Haster |
15:a6b1f4e65bf4 | 34 | |
Christopher Haster |
15:a6b1f4e65bf4 | 35 | subparser.set_defaults(command=thunk) |
Christopher Haster |
15:a6b1f4e65bf4 | 36 | return command |
Christopher Haster |
15:a6b1f4e65bf4 | 37 | return subcommand |
Christopher Haster |
15:a6b1f4e65bf4 | 38 | |
Christopher Haster |
15:a6b1f4e65bf4 | 39 | # Process execution |
Christopher Haster |
15:a6b1f4e65bf4 | 40 | class ProcessException(Exception): |
Christopher Haster |
15:a6b1f4e65bf4 | 41 | pass |
Christopher Haster |
15:a6b1f4e65bf4 | 42 | |
Christopher Haster |
15:a6b1f4e65bf4 | 43 | def popen(command, stdin=None, **kwargs): |
Christopher Haster |
15:a6b1f4e65bf4 | 44 | # print for debugging |
Christopher Haster |
15:a6b1f4e65bf4 | 45 | print ' '.join(command) |
Christopher Haster |
15:a6b1f4e65bf4 | 46 | proc = subprocess.Popen(command, **kwargs) |
Christopher Haster |
15:a6b1f4e65bf4 | 47 | |
Christopher Haster |
15:a6b1f4e65bf4 | 48 | if proc.wait() != 0: |
Christopher Haster |
15:a6b1f4e65bf4 | 49 | raise ProcessException(proc.returncode) |
Christopher Haster |
15:a6b1f4e65bf4 | 50 | |
Christopher Haster |
15:a6b1f4e65bf4 | 51 | def pquery(command, stdin=None, **kwargs): |
Christopher Haster |
15:a6b1f4e65bf4 | 52 | proc = subprocess.Popen(command, stdout=subprocess.PIPE, **kwargs) |
Christopher Haster |
15:a6b1f4e65bf4 | 53 | stdout, _ = proc.communicate(stdin) |
Christopher Haster |
15:a6b1f4e65bf4 | 54 | |
Christopher Haster |
15:a6b1f4e65bf4 | 55 | if proc.returncode != 0: |
Christopher Haster |
15:a6b1f4e65bf4 | 56 | raise ProcessException(proc.returncode) |
Christopher Haster |
15:a6b1f4e65bf4 | 57 | |
Christopher Haster |
15:a6b1f4e65bf4 | 58 | return stdout |
Christopher Haster |
15:a6b1f4e65bf4 | 59 | |
Christopher Haster |
15:a6b1f4e65bf4 | 60 | # Directory navigation |
Christopher Haster |
15:a6b1f4e65bf4 | 61 | @contextlib.contextmanager |
Christopher Haster |
15:a6b1f4e65bf4 | 62 | def cd(newdir): |
Christopher Haster |
15:a6b1f4e65bf4 | 63 | prevdir = os.getcwd() |
Christopher Haster |
15:a6b1f4e65bf4 | 64 | os.chdir(newdir) |
Christopher Haster |
15:a6b1f4e65bf4 | 65 | try: |
Christopher Haster |
15:a6b1f4e65bf4 | 66 | yield |
Christopher Haster |
15:a6b1f4e65bf4 | 67 | finally: |
Christopher Haster |
15:a6b1f4e65bf4 | 68 | os.chdir(prevdir) |
Christopher Haster |
15:a6b1f4e65bf4 | 69 | |
Christopher Haster |
15:a6b1f4e65bf4 | 70 | def iterlibs(dir=None): |
Christopher Haster |
15:a6b1f4e65bf4 | 71 | for root, dirs, files in os.walk(dir or os.getcwd()): |
Christopher Haster |
15:a6b1f4e65bf4 | 72 | if os.path.basename(root).startswith('.'): |
Christopher Haster |
15:a6b1f4e65bf4 | 73 | del dirs[:] |
Christopher Haster |
15:a6b1f4e65bf4 | 74 | continue |
Christopher Haster |
15:a6b1f4e65bf4 | 75 | |
Christopher Haster |
15:a6b1f4e65bf4 | 76 | for file in files: |
Christopher Haster |
15:a6b1f4e65bf4 | 77 | if file.startswith('.'): |
Christopher Haster |
15:a6b1f4e65bf4 | 78 | continue |
Christopher Haster |
15:a6b1f4e65bf4 | 79 | elif file.endswith('.lib'): |
Christopher Haster |
15:a6b1f4e65bf4 | 80 | with open(os.path.join(root, file)) as f: |
Christopher Haster |
15:a6b1f4e65bf4 | 81 | yield f.read().strip(), os.path.join(root, file[:-4]) |
Christopher Haster |
15:a6b1f4e65bf4 | 82 | if file[:-4] in dirs: |
Christopher Haster |
15:a6b1f4e65bf4 | 83 | dirs.remove(file[:-4]) |
Christopher Haster |
15:a6b1f4e65bf4 | 84 | |
Christopher Haster |
15:a6b1f4e65bf4 | 85 | def savelib(repo): |
Christopher Haster |
15:a6b1f4e65bf4 | 86 | print repo.name, '->', repo.url |
Christopher Haster |
15:a6b1f4e65bf4 | 87 | |
Christopher Haster |
15:a6b1f4e65bf4 | 88 | with open(repo.lib, 'w') as f: |
Christopher Haster |
15:a6b1f4e65bf4 | 89 | f.write(repo.url + '\n') |
Christopher Haster |
15:a6b1f4e65bf4 | 90 | |
Christopher Haster |
15:a6b1f4e65bf4 | 91 | |
Christopher Haster |
15:a6b1f4e65bf4 | 92 | # Handling for multiple version controls |
Christopher Haster |
35:ffcfa5ace437 | 93 | scms = OrderedDict() |
Christopher Haster |
35:ffcfa5ace437 | 94 | def scm(name): |
Christopher Haster |
35:ffcfa5ace437 | 95 | def scm(cls): |
Christopher Haster |
35:ffcfa5ace437 | 96 | scms[name] = cls() |
Christopher Haster |
35:ffcfa5ace437 | 97 | return cls |
Christopher Haster |
35:ffcfa5ace437 | 98 | return scm |
Christopher Haster |
35:ffcfa5ace437 | 99 | |
Christopher Haster |
35:ffcfa5ace437 | 100 | def staticclass(cls): |
Christopher Haster |
35:ffcfa5ace437 | 101 | for k, v in cls.__dict__.items(): |
Christopher Haster |
35:ffcfa5ace437 | 102 | if not k.startswith('__'): |
Christopher Haster |
35:ffcfa5ace437 | 103 | setattr(cls, k, staticmethod(v)) |
Christopher Haster |
35:ffcfa5ace437 | 104 | |
Christopher Haster |
35:ffcfa5ace437 | 105 | return cls |
Christopher Haster |
35:ffcfa5ace437 | 106 | |
Christopher Haster |
35:ffcfa5ace437 | 107 | @scm('hg') |
Christopher Haster |
35:ffcfa5ace437 | 108 | @staticclass |
Christopher Haster |
35:ffcfa5ace437 | 109 | class Hg(object): |
Christopher Haster |
35:ffcfa5ace437 | 110 | def clone(url, name=None, hash=None): |
Christopher Haster |
35:ffcfa5ace437 | 111 | popen(['hg', 'clone', url, name] + (['-u', hash] if hash else [])) |
Christopher Haster |
35:ffcfa5ace437 | 112 | |
Christopher Haster |
35:ffcfa5ace437 | 113 | def add(file): popen(['hg', 'add', file]) |
Christopher Haster |
35:ffcfa5ace437 | 114 | def remove(file): |
Christopher Haster |
35:ffcfa5ace437 | 115 | popen(['hg', 'rm', '-f', file]) |
Christopher Haster |
35:ffcfa5ace437 | 116 | try: |
Christopher Haster |
35:ffcfa5ace437 | 117 | os.remove(file) |
Christopher Haster |
35:ffcfa5ace437 | 118 | except OSError: |
Christopher Haster |
35:ffcfa5ace437 | 119 | pass |
Christopher Haster |
35:ffcfa5ace437 | 120 | |
Christopher Haster |
35:ffcfa5ace437 | 121 | def commit(): popen(['hg', 'commit']) |
Christopher Haster |
35:ffcfa5ace437 | 122 | def push(): popen(['hg', 'push']) |
Christopher Haster |
35:ffcfa5ace437 | 123 | def pull(hash=None): |
Christopher Haster |
35:ffcfa5ace437 | 124 | popen(['hg', 'pull']) |
Christopher Haster |
35:ffcfa5ace437 | 125 | popen(['hg', 'update'] + (['-r', hash] if hash else [])) |
Christopher Haster |
35:ffcfa5ace437 | 126 | |
Christopher Haster |
35:ffcfa5ace437 | 127 | def hash(): return pquery(['hg', 'id', '-i']).strip().strip('+') |
Christopher Haster |
35:ffcfa5ace437 | 128 | def modified(): return pquery(['hg', 'status', '-q']) |
Christopher Haster |
35:ffcfa5ace437 | 129 | |
Christopher Haster |
35:ffcfa5ace437 | 130 | @scm('git') |
Christopher Haster |
35:ffcfa5ace437 | 131 | @staticclass |
Christopher Haster |
35:ffcfa5ace437 | 132 | class Git(object): |
Christopher Haster |
35:ffcfa5ace437 | 133 | def clone(url, name=None, hash=None): |
Christopher Haster |
35:ffcfa5ace437 | 134 | popen(['git', 'clone', url, name]) |
Christopher Haster |
35:ffcfa5ace437 | 135 | if hash: |
Christopher Haster |
35:ffcfa5ace437 | 136 | popen(['git', 'checkout', hash]) |
Christopher Haster |
35:ffcfa5ace437 | 137 | |
Christopher Haster |
35:ffcfa5ace437 | 138 | def add(file): popen(['git', 'add', file]) |
Christopher Haster |
35:ffcfa5ace437 | 139 | def remove(file): popen(['git', 'rm', '-f', file]) |
Christopher Haster |
35:ffcfa5ace437 | 140 | def commit(): popen(['git', 'commit', '-a']) |
Christopher Haster |
35:ffcfa5ace437 | 141 | |
Christopher Haster |
35:ffcfa5ace437 | 142 | def hash(): return pquery(['git', 'rev-parse', '--short', 'HEAD']).strip() |
Christopher Haster |
35:ffcfa5ace437 | 143 | def modified(): return pquery(['git', 'diff', '--name-only', 'HEAD']) |
Christopher Haster |
35:ffcfa5ace437 | 144 | |
Christopher Haster |
35:ffcfa5ace437 | 145 | |
Christopher Haster |
35:ffcfa5ace437 | 146 | # Repository object |
Christopher Haster |
15:a6b1f4e65bf4 | 147 | class Repo(object): |
Christopher Haster |
15:a6b1f4e65bf4 | 148 | def __init__(self, path=None): |
Christopher Haster |
15:a6b1f4e65bf4 | 149 | self.path = path or os.getcwd() |
Christopher Haster |
15:a6b1f4e65bf4 | 150 | self.name = os.path.basename(self.path) |
Christopher Haster |
15:a6b1f4e65bf4 | 151 | self.update() |
Christopher Haster |
15:a6b1f4e65bf4 | 152 | |
Christopher Haster |
15:a6b1f4e65bf4 | 153 | @classmethod |
Christopher Haster |
15:a6b1f4e65bf4 | 154 | def fromurl(cls, url, name=None): |
Christopher Haster |
15:a6b1f4e65bf4 | 155 | repo = cls.__new__(cls) |
Christopher Haster |
22:599f5dc9c20e | 156 | url = url.strip() |
Christopher Haster |
15:a6b1f4e65bf4 | 157 | |
Christopher Haster |
15:a6b1f4e65bf4 | 158 | m = re.match('^(.*/([+a-zA-Z0-9_-]+)/?)(?:#(.*))?$', url) |
Christopher Haster |
15:a6b1f4e65bf4 | 159 | repo.repo = m.group(1) |
Christopher Haster |
15:a6b1f4e65bf4 | 160 | repo.name = name or m.group(2) |
Christopher Haster |
15:a6b1f4e65bf4 | 161 | repo.hash = m.group(3) |
Christopher Haster |
15:a6b1f4e65bf4 | 162 | |
Christopher Haster |
15:a6b1f4e65bf4 | 163 | repo.path = os.path.join(os.getcwd(), repo.name) |
Christopher Haster |
15:a6b1f4e65bf4 | 164 | return repo |
Christopher Haster |
15:a6b1f4e65bf4 | 165 | |
Christopher Haster |
15:a6b1f4e65bf4 | 166 | @property |
Christopher Haster |
15:a6b1f4e65bf4 | 167 | def lib(self): |
Christopher Haster |
15:a6b1f4e65bf4 | 168 | return self.path + '.lib' |
Christopher Haster |
15:a6b1f4e65bf4 | 169 | |
Christopher Haster |
15:a6b1f4e65bf4 | 170 | @property |
Christopher Haster |
15:a6b1f4e65bf4 | 171 | def url(self): |
Christopher Haster |
15:a6b1f4e65bf4 | 172 | if self.repo: |
Christopher Haster |
15:a6b1f4e65bf4 | 173 | if self.hash: |
Christopher Haster |
15:a6b1f4e65bf4 | 174 | return self.repo + '#' + self.hash |
Christopher Haster |
15:a6b1f4e65bf4 | 175 | else: |
Christopher Haster |
15:a6b1f4e65bf4 | 176 | return self.repo |
Christopher Haster |
15:a6b1f4e65bf4 | 177 | |
Christopher Haster |
15:a6b1f4e65bf4 | 178 | def update(self): |
Christopher Haster |
15:a6b1f4e65bf4 | 179 | if os.path.isdir(self.path): |
Christopher Haster |
15:a6b1f4e65bf4 | 180 | self.type = self.gettype() |
Christopher Haster |
35:ffcfa5ace437 | 181 | self.scm = self.getscm() |
Christopher Haster |
15:a6b1f4e65bf4 | 182 | self.hash = self.gethash() |
Christopher Haster |
15:a6b1f4e65bf4 | 183 | |
Christopher Haster |
15:a6b1f4e65bf4 | 184 | if os.path.isfile(self.lib): |
Christopher Haster |
15:a6b1f4e65bf4 | 185 | with open(self.lib) as f: |
Christopher Haster |
15:a6b1f4e65bf4 | 186 | temp = Repo.fromurl(f.read()) |
Christopher Haster |
15:a6b1f4e65bf4 | 187 | self.repo = temp.repo |
Christopher Haster |
15:a6b1f4e65bf4 | 188 | |
Christopher Haster |
15:a6b1f4e65bf4 | 189 | def gettype(self): |
Christopher Haster |
15:a6b1f4e65bf4 | 190 | for type, dir in [('hg', '.hg'), ('git', '.git')]: |
Christopher Haster |
15:a6b1f4e65bf4 | 191 | if os.path.isdir(os.path.join(self.path, dir)): |
Christopher Haster |
15:a6b1f4e65bf4 | 192 | return type |
Christopher Haster |
15:a6b1f4e65bf4 | 193 | |
Christopher Haster |
35:ffcfa5ace437 | 194 | def getscm(self): |
Christopher Haster |
35:ffcfa5ace437 | 195 | return scms[self.type] |
Christopher Haster |
35:ffcfa5ace437 | 196 | |
Christopher Haster |
15:a6b1f4e65bf4 | 197 | def gethash(self): |
Christopher Haster |
15:a6b1f4e65bf4 | 198 | with cd(self.path): |
Christopher Haster |
35:ffcfa5ace437 | 199 | return self.scm.hash() |
Christopher Haster |
15:a6b1f4e65bf4 | 200 | |
Christopher Haster |
15:a6b1f4e65bf4 | 201 | # Clone command |
Christopher Haster |
15:a6b1f4e65bf4 | 202 | @subcommand('import', 'url', 'name?', |
Christopher Haster |
15:a6b1f4e65bf4 | 203 | help='recursively import a repository') |
Christopher Haster |
15:a6b1f4e65bf4 | 204 | def import_(url, name=None): |
Christopher Haster |
15:a6b1f4e65bf4 | 205 | repo = Repo.fromurl(url, name) |
Christopher Haster |
15:a6b1f4e65bf4 | 206 | |
Christopher Haster |
35:ffcfa5ace437 | 207 | for scm in scms.values(): |
Christopher Haster |
15:a6b1f4e65bf4 | 208 | try: |
Christopher Haster |
35:ffcfa5ace437 | 209 | scm.clone(repo.repo, repo.path, repo.hash) |
Christopher Haster |
15:a6b1f4e65bf4 | 210 | break |
Christopher Haster |
35:ffcfa5ace437 | 211 | except ProcessException: |
Christopher Haster |
15:a6b1f4e65bf4 | 212 | pass |
Christopher Haster |
15:a6b1f4e65bf4 | 213 | |
Christopher Haster |
15:a6b1f4e65bf4 | 214 | repo.update() |
Christopher Haster |
15:a6b1f4e65bf4 | 215 | |
Christopher Haster |
15:a6b1f4e65bf4 | 216 | with cd(repo.path): |
Christopher Haster |
15:a6b1f4e65bf4 | 217 | for url, lib in iterlibs(): |
Christopher Haster |
15:a6b1f4e65bf4 | 218 | import_(url, lib) |
Christopher Haster |
15:a6b1f4e65bf4 | 219 | |
Christopher Haster |
19:6ace1080b8bb | 220 | if (not os.path.isfile('mbed_settings.py') and |
Christopher Haster |
19:6ace1080b8bb | 221 | os.path.isfile('mbed-os/tools/settings.py')): |
screamer | 30:dcc9ff39aee3 | 222 | shutil.copy('mbed-os/tools/default_settings.py', 'mbed_settings.py') |
Christopher Haster |
19:6ace1080b8bb | 223 | |
Christopher Haster |
15:a6b1f4e65bf4 | 224 | # Deploy command |
Christopher Haster |
15:a6b1f4e65bf4 | 225 | @subcommand('deploy', |
Christopher Haster |
15:a6b1f4e65bf4 | 226 | help='recursively import libraries in current directory') |
Christopher Haster |
15:a6b1f4e65bf4 | 227 | def deploy(): |
Christopher Haster |
15:a6b1f4e65bf4 | 228 | for url, lib in iterlibs(): |
Christopher Haster |
15:a6b1f4e65bf4 | 229 | import_(url, lib) |
Christopher Haster |
15:a6b1f4e65bf4 | 230 | |
Christopher Haster |
15:a6b1f4e65bf4 | 231 | # Install/uninstall command |
Christopher Haster |
15:a6b1f4e65bf4 | 232 | @subcommand('add', 'url', 'name?', |
Christopher Haster |
15:a6b1f4e65bf4 | 233 | help='add a library to the current repository') |
Christopher Haster |
15:a6b1f4e65bf4 | 234 | def add(url, name): |
Christopher Haster |
15:a6b1f4e65bf4 | 235 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 236 | repo = Repo.fromurl(url, name) |
Christopher Haster |
15:a6b1f4e65bf4 | 237 | |
Christopher Haster |
15:a6b1f4e65bf4 | 238 | import_(url) |
Christopher Haster |
15:a6b1f4e65bf4 | 239 | |
Christopher Haster |
15:a6b1f4e65bf4 | 240 | repo.update() |
Christopher Haster |
15:a6b1f4e65bf4 | 241 | savelib(repo) |
Christopher Haster |
15:a6b1f4e65bf4 | 242 | |
Christopher Haster |
35:ffcfa5ace437 | 243 | repo.scm.add(repo.lib) |
Christopher Haster |
15:a6b1f4e65bf4 | 244 | |
Christopher Haster |
15:a6b1f4e65bf4 | 245 | @subcommand('remove', 'library', |
Christopher Haster |
15:a6b1f4e65bf4 | 246 | help='remove a library from the current repository folder') |
Christopher Haster |
15:a6b1f4e65bf4 | 247 | def remove(library): |
Christopher Haster |
15:a6b1f4e65bf4 | 248 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 249 | repo = Repo(library) |
Christopher Haster |
15:a6b1f4e65bf4 | 250 | |
Christopher Haster |
35:ffcfa5ace437 | 251 | cwd.scm.remove(repo.lib) |
Christopher Haster |
35:ffcfa5ace437 | 252 | shutil.rmtree(repo.path) |
Christopher Haster |
15:a6b1f4e65bf4 | 253 | |
Christopher Haster |
15:a6b1f4e65bf4 | 254 | # Publish command |
Christopher Haster |
15:a6b1f4e65bf4 | 255 | @subcommand('publish', |
Christopher Haster |
15:a6b1f4e65bf4 | 256 | help='recursively publish changes to remote repositories') |
Christopher Haster |
18:1b4252106474 | 257 | def publish(always=True): |
Christopher Haster |
15:a6b1f4e65bf4 | 258 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 259 | |
Christopher Haster |
15:a6b1f4e65bf4 | 260 | for url, lib in iterlibs(): |
Christopher Haster |
15:a6b1f4e65bf4 | 261 | if os.path.isdir(lib): |
Christopher Haster |
15:a6b1f4e65bf4 | 262 | with cd(lib): |
Christopher Haster |
18:1b4252106474 | 263 | publish(False) |
Christopher Haster |
15:a6b1f4e65bf4 | 264 | |
Christopher Haster |
17:1e487c450f06 | 265 | synch() |
Christopher Haster |
35:ffcfa5ace437 | 266 | modified = cwd.scm.modified() |
Christopher Haster |
17:1e487c450f06 | 267 | |
Christopher Haster |
17:1e487c450f06 | 268 | if modified: |
Christopher Haster |
17:1e487c450f06 | 269 | print cwd.path |
Christopher Haster |
17:1e487c450f06 | 270 | print 'Uncommitted changes in %s' % cwd.name |
Christopher Haster |
24:b29dad301edd | 271 | raw_input('Press enter to commit and push ') |
Christopher Haster |
17:1e487c450f06 | 272 | |
Christopher Haster |
35:ffcfa5ace437 | 273 | cwd.scm.commit() |
Christopher Haster |
18:1b4252106474 | 274 | |
Christopher Haster |
18:1b4252106474 | 275 | if modified or always: |
Christopher Haster |
18:1b4252106474 | 276 | try: |
Christopher Haster |
35:ffcfa5ace437 | 277 | cwd.scm.push() |
Christopher Haster |
18:1b4252106474 | 278 | except ProcessException as e: |
Christopher Haster |
18:1b4252106474 | 279 | sys.exit(e[0]) |
Christopher Haster |
15:a6b1f4e65bf4 | 280 | |
Christopher Haster |
20:84d6e18cbc20 | 281 | # Update command |
Christopher Haster |
20:84d6e18cbc20 | 282 | @subcommand('update', 'ref?', |
Christopher Haster |
20:84d6e18cbc20 | 283 | help='recursively updates libraries and current repository') |
Christopher Haster |
20:84d6e18cbc20 | 284 | def update(ref=None): |
Christopher Haster |
20:84d6e18cbc20 | 285 | cwd = Repo() |
Christopher Haster |
35:ffcfa5ace437 | 286 | cwd.scm.pull(ref) |
Christopher Haster |
20:84d6e18cbc20 | 287 | |
Christopher Haster |
20:84d6e18cbc20 | 288 | for url, lib in iterlibs(): |
Christopher Haster |
20:84d6e18cbc20 | 289 | repo = Repo.fromurl(url, lib) |
Christopher Haster |
20:84d6e18cbc20 | 290 | if os.path.isdir(lib): |
Christopher Haster |
20:84d6e18cbc20 | 291 | with cd(repo.path): |
Christopher Haster |
20:84d6e18cbc20 | 292 | update(repo.hash) |
Christopher Haster |
20:84d6e18cbc20 | 293 | else: |
Christopher Haster |
20:84d6e18cbc20 | 294 | import_(url, lib) |
Christopher Haster |
20:84d6e18cbc20 | 295 | |
Christopher Haster |
15:a6b1f4e65bf4 | 296 | # Synch command |
Christopher Haster |
15:a6b1f4e65bf4 | 297 | @subcommand('synch', |
Christopher Haster |
15:a6b1f4e65bf4 | 298 | help='synchronize lib files') |
Christopher Haster |
15:a6b1f4e65bf4 | 299 | def synch(): |
Christopher Haster |
15:a6b1f4e65bf4 | 300 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 301 | |
Christopher Haster |
15:a6b1f4e65bf4 | 302 | for url, lib in iterlibs(): |
Christopher Haster |
15:a6b1f4e65bf4 | 303 | repo = Repo.fromurl(url, lib) |
Christopher Haster |
15:a6b1f4e65bf4 | 304 | repo.update() |
Christopher Haster |
22:599f5dc9c20e | 305 | if url == repo.url: |
Christopher Haster |
15:a6b1f4e65bf4 | 306 | continue |
Christopher Haster |
15:a6b1f4e65bf4 | 307 | |
Christopher Haster |
15:a6b1f4e65bf4 | 308 | savelib(repo) |
Christopher Haster |
15:a6b1f4e65bf4 | 309 | |
Christopher Haster |
15:a6b1f4e65bf4 | 310 | # Compile command |
Christopher Haster |
15:a6b1f4e65bf4 | 311 | @subcommand('compile', 'args*', |
Christopher Haster |
15:a6b1f4e65bf4 | 312 | help='compile project using workspace_tools') |
Christopher Haster |
15:a6b1f4e65bf4 | 313 | def compile(args): |
Christopher Haster |
15:a6b1f4e65bf4 | 314 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 315 | |
Christopher Haster |
15:a6b1f4e65bf4 | 316 | if not os.path.isdir('mbed-os'): |
Christopher Haster |
15:a6b1f4e65bf4 | 317 | sys.stderr.write('Warning! mbed-os not found?') |
Christopher Haster |
15:a6b1f4e65bf4 | 318 | sys.exit(-1) |
Christopher Haster |
15:a6b1f4e65bf4 | 319 | |
Christopher Haster |
21:1a3f920b6f07 | 320 | macros = [] |
Christopher Haster |
15:a6b1f4e65bf4 | 321 | if os.path.isfile('MACROS.txt'): |
Christopher Haster |
15:a6b1f4e65bf4 | 322 | with open('MACROS.txt') as f: |
Christopher Haster |
15:a6b1f4e65bf4 | 323 | macros = f.read().splitlines() |
Christopher Haster |
15:a6b1f4e65bf4 | 324 | |
Christopher Haster |
15:a6b1f4e65bf4 | 325 | env = os.environ.copy() |
Christopher Haster |
15:a6b1f4e65bf4 | 326 | env['PYTHONPATH'] = '.' |
Christopher Haster |
15:a6b1f4e65bf4 | 327 | popen(['python', 'mbed-os/tools/make.py'] |
Christopher Haster |
15:a6b1f4e65bf4 | 328 | + list(chain.from_iterable(izip(repeat('-D'), macros))) |
Christopher Haster |
15:a6b1f4e65bf4 | 329 | + ['--source=%s' % cwd.path, |
Christopher Haster |
15:a6b1f4e65bf4 | 330 | '--build=%s' % os.path.join(cwd.path, '.build')] |
Christopher Haster |
15:a6b1f4e65bf4 | 331 | + args, |
Christopher Haster |
15:a6b1f4e65bf4 | 332 | env=env) |
Christopher Haster |
15:a6b1f4e65bf4 | 333 | |
Christopher Haster |
15:a6b1f4e65bf4 | 334 | # Export command |
Christopher Haster |
15:a6b1f4e65bf4 | 335 | @subcommand('export', 'args*', |
Christopher Haster |
15:a6b1f4e65bf4 | 336 | help='generate project files') |
Christopher Haster |
15:a6b1f4e65bf4 | 337 | def export(args): |
Christopher Haster |
15:a6b1f4e65bf4 | 338 | cwd = Repo() |
Christopher Haster |
15:a6b1f4e65bf4 | 339 | |
Christopher Haster |
15:a6b1f4e65bf4 | 340 | if not os.path.isdir('mbed-os'): |
Christopher Haster |
15:a6b1f4e65bf4 | 341 | sys.stderr.write('Warning! mbed-os not found?') |
Christopher Haster |
15:a6b1f4e65bf4 | 342 | sys.exit(-1) |
Christopher Haster |
15:a6b1f4e65bf4 | 343 | |
Christopher Haster |
18:1b4252106474 | 344 | env = os.environ.copy() |
Christopher Haster |
18:1b4252106474 | 345 | env['PYTHONPATH'] = '.' |
Christopher Haster |
15:a6b1f4e65bf4 | 346 | popen(['python', 'mbed-os/tools/project.py', |
Christopher Haster |
17:1e487c450f06 | 347 | '--source=%s' % cwd.path] |
Christopher Haster |
18:1b4252106474 | 348 | + args, |
Christopher Haster |
18:1b4252106474 | 349 | env=env) |
Christopher Haster |
15:a6b1f4e65bf4 | 350 | |
Christopher Haster |
15:a6b1f4e65bf4 | 351 | # Parse/run command |
Christopher Haster |
15:a6b1f4e65bf4 | 352 | args, remainder = parser.parse_known_args() |
Christopher Haster |
15:a6b1f4e65bf4 | 353 | status = args.command(args) |
Christopher Haster |
15:a6b1f4e65bf4 | 354 | sys.exit(status or 0) |
Christopher Haster |
15:a6b1f4e65bf4 | 355 |