Morpheus / Mbed OS mbed-Client-Morpheus-hg

Dependencies:   mbed-os

Committer:
Christopher Haster
Date:
Wed Mar 30 15:34:56 2016 -0500
Revision:
41:59e9d808ee05
Parent:
40:2446665dfdf8
Child:
42:58b35941ebd0
Added defines for export script

Who changed what in which revision?

UserRevisionLine numberNew 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 # Handling for multiple version controls
Christopher Haster 35:ffcfa5ace437 71 scms = OrderedDict()
Christopher Haster 35:ffcfa5ace437 72 def scm(name):
Christopher Haster 35:ffcfa5ace437 73 def scm(cls):
Christopher Haster 35:ffcfa5ace437 74 scms[name] = cls()
Christopher Haster 35:ffcfa5ace437 75 return cls
Christopher Haster 35:ffcfa5ace437 76 return scm
Christopher Haster 35:ffcfa5ace437 77
Christopher Haster 35:ffcfa5ace437 78 def staticclass(cls):
Christopher Haster 35:ffcfa5ace437 79 for k, v in cls.__dict__.items():
Christopher Haster 36:5f4546dde73b 80 if hasattr(v, '__call__') and not k.startswith('__'):
Christopher Haster 35:ffcfa5ace437 81 setattr(cls, k, staticmethod(v))
Christopher Haster 35:ffcfa5ace437 82
Christopher Haster 35:ffcfa5ace437 83 return cls
Christopher Haster 35:ffcfa5ace437 84
Christopher Haster 35:ffcfa5ace437 85 @scm('hg')
Christopher Haster 35:ffcfa5ace437 86 @staticclass
Christopher Haster 35:ffcfa5ace437 87 class Hg(object):
Christopher Haster 41:59e9d808ee05 88 exclude = '.hg/exclude'
Christopher Haster 41:59e9d808ee05 89
Christopher Haster 35:ffcfa5ace437 90 def clone(url, name=None, hash=None):
Christopher Haster 35:ffcfa5ace437 91 popen(['hg', 'clone', url, name] + (['-u', hash] if hash else []))
Christopher Haster 35:ffcfa5ace437 92
Christopher Haster 35:ffcfa5ace437 93 def add(file): popen(['hg', 'add', file])
Christopher Haster 35:ffcfa5ace437 94 def remove(file):
Christopher Haster 35:ffcfa5ace437 95 popen(['hg', 'rm', '-f', file])
Christopher Haster 35:ffcfa5ace437 96 try:
Christopher Haster 35:ffcfa5ace437 97 os.remove(file)
Christopher Haster 35:ffcfa5ace437 98 except OSError:
Christopher Haster 35:ffcfa5ace437 99 pass
Christopher Haster 35:ffcfa5ace437 100
Christopher Haster 35:ffcfa5ace437 101 def commit(): popen(['hg', 'commit'])
Christopher Haster 35:ffcfa5ace437 102 def push(): popen(['hg', 'push'])
Christopher Haster 35:ffcfa5ace437 103 def pull(hash=None):
Christopher Haster 35:ffcfa5ace437 104 popen(['hg', 'pull'])
Christopher Haster 35:ffcfa5ace437 105 popen(['hg', 'update'] + (['-r', hash] if hash else []))
Christopher Haster 35:ffcfa5ace437 106
Christopher Haster 35:ffcfa5ace437 107 def hash(): return pquery(['hg', 'id', '-i']).strip().strip('+')
Christopher Haster 36:5f4546dde73b 108 def dirty(): return pquery(['hg', 'status', '-q'])
Christopher Haster 35:ffcfa5ace437 109
Christopher Haster 35:ffcfa5ace437 110 @scm('git')
Christopher Haster 35:ffcfa5ace437 111 @staticclass
Christopher Haster 35:ffcfa5ace437 112 class Git(object):
Christopher Haster 41:59e9d808ee05 113 exclude = '.git/info/exclude'
Christopher Haster 41:59e9d808ee05 114
Christopher Haster 35:ffcfa5ace437 115 def clone(url, name=None, hash=None):
Christopher Haster 35:ffcfa5ace437 116 popen(['git', 'clone', url, name])
Christopher Haster 35:ffcfa5ace437 117 if hash:
Christopher Haster 39:8d6f31570710 118 with cd(name):
Christopher Haster 39:8d6f31570710 119 popen(['git', 'checkout', '-q', hash])
Christopher Haster 35:ffcfa5ace437 120
Christopher Haster 35:ffcfa5ace437 121 def add(file): popen(['git', 'add', file])
Christopher Haster 35:ffcfa5ace437 122 def remove(file): popen(['git', 'rm', '-f', file])
Christopher Haster 39:8d6f31570710 123
Christopher Haster 35:ffcfa5ace437 124 def commit(): popen(['git', 'commit', '-a'])
Christopher Haster 39:8d6f31570710 125 def push(): popen(['git', 'push', '--all'])
Christopher Haster 39:8d6f31570710 126 def pull(hash=None):
Christopher Haster 39:8d6f31570710 127 popen(['git', 'fetch', 'origin'])
Christopher Haster 39:8d6f31570710 128 popen(['git', 'merge'] + ([hash] if hash else []))
Christopher Haster 35:ffcfa5ace437 129
Christopher Haster 35:ffcfa5ace437 130 def hash(): return pquery(['git', 'rev-parse', '--short', 'HEAD']).strip()
Christopher Haster 36:5f4546dde73b 131 def dirty(): return pquery(['git', 'diff', '--name-only', 'HEAD'])
Christopher Haster 40:2446665dfdf8 132
Christopher Haster 40:2446665dfdf8 133 def ignore(regex):
Christopher Haster 40:2446665dfdf8 134 with open('.git/info/exclude', 'a') as f:
Christopher Haster 40:2446665dfdf8 135 f.write(regex)
Christopher Haster 40:2446665dfdf8 136
Christopher Haster 35:ffcfa5ace437 137
Christopher Haster 35:ffcfa5ace437 138 # Repository object
Christopher Haster 15:a6b1f4e65bf4 139 class Repo(object):
Christopher Haster 36:5f4546dde73b 140 @classmethod
Christopher Haster 36:5f4546dde73b 141 def fromurl(cls, url, path=None):
Christopher Haster 36:5f4546dde73b 142 repo = cls()
Christopher Haster 36:5f4546dde73b 143
Christopher Haster 36:5f4546dde73b 144 m = re.match('^(.*/([+a-zA-Z0-9_-]+)/?)(?:#(.*))?$', url.strip())
Christopher Haster 36:5f4546dde73b 145 repo.name = os.path.basename(path or m.group(2))
Christopher Haster 36:5f4546dde73b 146 repo.path = os.path.abspath(
Christopher Haster 36:5f4546dde73b 147 path or os.path.join(os.getcwd(), repo.name))
Christopher Haster 36:5f4546dde73b 148
Christopher Haster 36:5f4546dde73b 149 repo.repo = m.group(1)
Christopher Haster 36:5f4546dde73b 150 repo.hash = m.group(3)
Christopher Haster 36:5f4546dde73b 151 return repo
Christopher Haster 15:a6b1f4e65bf4 152
Christopher Haster 15:a6b1f4e65bf4 153 @classmethod
Christopher Haster 36:5f4546dde73b 154 def fromlib(cls, lib=None):
Christopher Haster 36:5f4546dde73b 155 assert lib.endswith('.lib')
Christopher Haster 36:5f4546dde73b 156 with open(lib) as f:
Christopher Haster 36:5f4546dde73b 157 return cls.fromurl(f.read(), lib[:-4])
Christopher Haster 15:a6b1f4e65bf4 158
Christopher Haster 36:5f4546dde73b 159 @classmethod
Christopher Haster 36:5f4546dde73b 160 def fromrepo(cls, path=None):
Christopher Haster 36:5f4546dde73b 161 repo = cls()
Christopher Haster 36:5f4546dde73b 162 repo.path = os.path.abspath(path or os.getcwd())
Christopher Haster 36:5f4546dde73b 163 repo.name = os.path.basename(repo.path)
Christopher Haster 15:a6b1f4e65bf4 164
Christopher Haster 36:5f4546dde73b 165 repo.synch()
Christopher Haster 15:a6b1f4e65bf4 166 return repo
Christopher Haster 15:a6b1f4e65bf4 167
Christopher Haster 15:a6b1f4e65bf4 168 @property
Christopher Haster 15:a6b1f4e65bf4 169 def lib(self):
Christopher Haster 15:a6b1f4e65bf4 170 return self.path + '.lib'
Christopher Haster 15:a6b1f4e65bf4 171
Christopher Haster 15:a6b1f4e65bf4 172 @property
Christopher Haster 15:a6b1f4e65bf4 173 def url(self):
Christopher Haster 15:a6b1f4e65bf4 174 if self.repo:
Christopher Haster 36:5f4546dde73b 175 return self.repo + ('#'+self.hash if self.hash else '')
Christopher Haster 15:a6b1f4e65bf4 176
Christopher Haster 36:5f4546dde73b 177 def synch(self):
Christopher Haster 15:a6b1f4e65bf4 178 if os.path.isdir(self.path):
Christopher Haster 39:8d6f31570710 179 try:
Christopher Haster 39:8d6f31570710 180 self.scm = self.getscm()
Christopher Haster 39:8d6f31570710 181 self.hash = self.gethash()
Christopher Haster 39:8d6f31570710 182 self.libs = list(self.getlibs())
Christopher Haster 39:8d6f31570710 183 except ProcessException:
Christopher Haster 39:8d6f31570710 184 pass
Christopher Haster 15:a6b1f4e65bf4 185
Christopher Haster 37:bf73ffd98cca 186 if os.path.isfile(self.lib):
Christopher Haster 39:8d6f31570710 187 try:
Christopher Haster 39:8d6f31570710 188 self.repo = self.getrepo()
Christopher Haster 39:8d6f31570710 189 except ProcessException:
Christopher Haster 39:8d6f31570710 190 pass
Christopher Haster 37:bf73ffd98cca 191
Christopher Haster 35:ffcfa5ace437 192 def getscm(self):
Christopher Haster 36:5f4546dde73b 193 for name, scm in scms.items():
Christopher Haster 36:5f4546dde73b 194 if os.path.isdir(os.path.join(self.path, '.'+name)):
Christopher Haster 36:5f4546dde73b 195 return scm
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 36:5f4546dde73b 201 def getlibs(self):
Christopher Haster 36:5f4546dde73b 202 for root, dirs, files in os.walk(self.path):
Christopher Haster 36:5f4546dde73b 203 dirs[:] = [d for d in dirs if not d.startswith('.')]
Christopher Haster 36:5f4546dde73b 204 files[:] = [f for f in files if not f.startswith('.')]
Christopher Haster 36:5f4546dde73b 205
Christopher Haster 36:5f4546dde73b 206 for file in files:
Christopher Haster 36:5f4546dde73b 207 if file.endswith('.lib'):
Christopher Haster 36:5f4546dde73b 208 yield Repo.fromlib(os.path.join(root, file))
Christopher Haster 36:5f4546dde73b 209
Christopher Haster 37:bf73ffd98cca 210 def getrepo(self):
Christopher Haster 37:bf73ffd98cca 211 with open(self.lib) as f:
Christopher Haster 37:bf73ffd98cca 212 return Repo.fromurl(f.read()).repo
Christopher Haster 37:bf73ffd98cca 213
Christopher Haster 36:5f4546dde73b 214 def write(self):
Christopher Haster 38:0ca5eea23af9 215 print self.name, '->', self.url
Christopher Haster 36:5f4546dde73b 216
Christopher Haster 38:0ca5eea23af9 217 if os.path.isfile(self.lib):
Christopher Haster 38:0ca5eea23af9 218 with open(self.lib) as f:
Christopher Haster 38:0ca5eea23af9 219 if f.read().strip() == self.url.strip():
Christopher Haster 38:0ca5eea23af9 220 return
Christopher Haster 36:5f4546dde73b 221
Christopher Haster 38:0ca5eea23af9 222 with open(self.lib, 'w') as f:
Christopher Haster 38:0ca5eea23af9 223 f.write(self.url + '\n')
Christopher Haster 36:5f4546dde73b 224
Christopher Haster 15:a6b1f4e65bf4 225 # Clone command
Christopher Haster 15:a6b1f4e65bf4 226 @subcommand('import', 'url', 'name?',
Christopher Haster 15:a6b1f4e65bf4 227 help='recursively import a repository')
Christopher Haster 36:5f4546dde73b 228 def import_(url, path=None):
Christopher Haster 36:5f4546dde73b 229 repo = Repo.fromurl(url, path)
Christopher Haster 15:a6b1f4e65bf4 230
Christopher Haster 35:ffcfa5ace437 231 for scm in scms.values():
Christopher Haster 15:a6b1f4e65bf4 232 try:
Christopher Haster 35:ffcfa5ace437 233 scm.clone(repo.repo, repo.path, repo.hash)
Christopher Haster 15:a6b1f4e65bf4 234 break
Christopher Haster 35:ffcfa5ace437 235 except ProcessException:
Christopher Haster 15:a6b1f4e65bf4 236 pass
Christopher Haster 15:a6b1f4e65bf4 237
Christopher Haster 36:5f4546dde73b 238 repo.synch()
Christopher Haster 15:a6b1f4e65bf4 239
Christopher Haster 15:a6b1f4e65bf4 240 with cd(repo.path):
Christopher Haster 36:5f4546dde73b 241 for lib in repo.libs:
Christopher Haster 36:5f4546dde73b 242 import_(lib.url, lib.path)
Christopher Haster 40:2446665dfdf8 243 #repo.scm.ignore(lib.path)
Christopher Haster 15:a6b1f4e65bf4 244
Christopher Haster 19:6ace1080b8bb 245 if (not os.path.isfile('mbed_settings.py') and
Christopher Haster 19:6ace1080b8bb 246 os.path.isfile('mbed-os/tools/settings.py')):
screamer 30:dcc9ff39aee3 247 shutil.copy('mbed-os/tools/default_settings.py', 'mbed_settings.py')
Christopher Haster 19:6ace1080b8bb 248
Christopher Haster 15:a6b1f4e65bf4 249 # Deploy command
Christopher Haster 15:a6b1f4e65bf4 250 @subcommand('deploy',
Christopher Haster 15:a6b1f4e65bf4 251 help='recursively import libraries in current directory')
Christopher Haster 15:a6b1f4e65bf4 252 def deploy():
Christopher Haster 36:5f4546dde73b 253 repo = Repo.fromrepo()
Christopher Haster 36:5f4546dde73b 254 for lib in repo.libs:
Christopher Haster 36:5f4546dde73b 255 import_(lib.url, lib.path)
Christopher Haster 15:a6b1f4e65bf4 256
Christopher Haster 15:a6b1f4e65bf4 257 # Install/uninstall command
Christopher Haster 15:a6b1f4e65bf4 258 @subcommand('add', 'url', 'name?',
Christopher Haster 15:a6b1f4e65bf4 259 help='add a library to the current repository')
Christopher Haster 36:5f4546dde73b 260 def add(url, path=None):
Christopher Haster 36:5f4546dde73b 261 repo = Repo.fromrepo()
Christopher Haster 15:a6b1f4e65bf4 262
Christopher Haster 36:5f4546dde73b 263 lib = Repo.fromurl(url, path)
Christopher Haster 36:5f4546dde73b 264 import_(lib.url, lib.path)
Christopher Haster 36:5f4546dde73b 265 lib.synch()
Christopher Haster 15:a6b1f4e65bf4 266
Christopher Haster 36:5f4546dde73b 267 lib.write()
Christopher Haster 36:5f4546dde73b 268 repo.scm.add(lib.lib)
Christopher Haster 40:2446665dfdf8 269 #repo.scm.ignore(lib.path)
Christopher Haster 15:a6b1f4e65bf4 270
Christopher Haster 36:5f4546dde73b 271 @subcommand('remove', 'path',
Christopher Haster 15:a6b1f4e65bf4 272 help='remove a library from the current repository folder')
Christopher Haster 36:5f4546dde73b 273 def remove(path):
Christopher Haster 36:5f4546dde73b 274 repo = Repo.fromrepo()
Christopher Haster 36:5f4546dde73b 275 lib = Repo.fromrepo(path)
Christopher Haster 15:a6b1f4e65bf4 276
Christopher Haster 36:5f4546dde73b 277 repo.scm.remove(lib.lib)
Christopher Haster 36:5f4546dde73b 278 shutil.rmtree(lib.path)
Christopher Haster 15:a6b1f4e65bf4 279
Christopher Haster 15:a6b1f4e65bf4 280 # Publish command
Christopher Haster 15:a6b1f4e65bf4 281 @subcommand('publish',
Christopher Haster 15:a6b1f4e65bf4 282 help='recursively publish changes to remote repositories')
Christopher Haster 18:1b4252106474 283 def publish(always=True):
Christopher Haster 36:5f4546dde73b 284 repo = Repo.fromrepo()
Christopher Haster 36:5f4546dde73b 285 for lib in repo.libs:
Christopher Haster 36:5f4546dde73b 286 with cd(lib.path):
Christopher Haster 36:5f4546dde73b 287 publish(False)
Christopher Haster 36:5f4546dde73b 288 synch()
Christopher Haster 15:a6b1f4e65bf4 289
Christopher Haster 36:5f4546dde73b 290 dirty = repo.scm.dirty()
Christopher Haster 17:1e487c450f06 291
Christopher Haster 36:5f4546dde73b 292 if dirty:
Christopher Haster 36:5f4546dde73b 293 print 'Uncommitted changes in %s (%s)' % (repo.name, repo.path)
Christopher Haster 24:b29dad301edd 294 raw_input('Press enter to commit and push ')
Christopher Haster 36:5f4546dde73b 295 repo.scm.commit()
Christopher Haster 17:1e487c450f06 296
Christopher Haster 36:5f4546dde73b 297 if dirty or always:
Christopher Haster 18:1b4252106474 298 try:
Christopher Haster 36:5f4546dde73b 299 repo.scm.push()
Christopher Haster 18:1b4252106474 300 except ProcessException as e:
Christopher Haster 18:1b4252106474 301 sys.exit(e[0])
Christopher Haster 15:a6b1f4e65bf4 302
Christopher Haster 20:84d6e18cbc20 303 # Update command
Christopher Haster 20:84d6e18cbc20 304 @subcommand('update', 'ref?',
Christopher Haster 20:84d6e18cbc20 305 help='recursively updates libraries and current repository')
Christopher Haster 20:84d6e18cbc20 306 def update(ref=None):
Christopher Haster 36:5f4546dde73b 307 repo = Repo.fromrepo()
Christopher Haster 36:5f4546dde73b 308 repo.scm.pull(ref)
Christopher Haster 36:5f4546dde73b 309
Christopher Haster 36:5f4546dde73b 310 for lib in repo.libs:
Christopher Haster 37:bf73ffd98cca 311 if (not os.path.isfile(lib.lib) or
Christopher Haster 37:bf73ffd98cca 312 lib.repo != Repo.fromrepo(lib.path).repo):
Christopher Haster 36:5f4546dde73b 313 with cd(lib.path):
Christopher Haster 36:5f4546dde73b 314 if lib.cwd.dirty():
Christopher Haster 37:bf73ffd98cca 315 sys.stderr.write('Uncommitted changes in %s (%s)\n'
Christopher Haster 36:5f4546dde73b 316 % (lib.name, lib.path))
Christopher Haster 36:5f4546dde73b 317 sys.exit(1)
Christopher Haster 20:84d6e18cbc20 318
Christopher Haster 36:5f4546dde73b 319 shutil.rmtree(lib.path)
Christopher Haster 36:5f4546dde73b 320
Christopher Haster 36:5f4546dde73b 321 repo.synch()
Christopher Haster 36:5f4546dde73b 322
Christopher Haster 36:5f4546dde73b 323 for lib in repo.libs:
Christopher Haster 36:5f4546dde73b 324 if os.path.isdir(lib.path):
Christopher Haster 36:5f4546dde73b 325 with cd(lib.path):
Christopher Haster 36:5f4546dde73b 326 update(lib.hash)
Christopher Haster 20:84d6e18cbc20 327 else:
Christopher Haster 36:5f4546dde73b 328 import_(lib.url, lib.path)
Christopher Haster 20:84d6e18cbc20 329
Christopher Haster 15:a6b1f4e65bf4 330 # Synch command
Christopher Haster 15:a6b1f4e65bf4 331 @subcommand('synch',
Christopher Haster 15:a6b1f4e65bf4 332 help='synchronize lib files')
Christopher Haster 15:a6b1f4e65bf4 333 def synch():
Christopher Haster 36:5f4546dde73b 334 repo = Repo.fromrepo()
Christopher Haster 36:5f4546dde73b 335 for lib in repo.libs:
Christopher Haster 36:5f4546dde73b 336 lib.synch()
Christopher Haster 36:5f4546dde73b 337 lib.save()
Christopher Haster 15:a6b1f4e65bf4 338
Christopher Haster 15:a6b1f4e65bf4 339 # Compile command
Christopher Haster 15:a6b1f4e65bf4 340 @subcommand('compile', 'args*',
Christopher Haster 15:a6b1f4e65bf4 341 help='compile project using workspace_tools')
Christopher Haster 15:a6b1f4e65bf4 342 def compile(args):
Christopher Haster 15:a6b1f4e65bf4 343 if not os.path.isdir('mbed-os'):
Christopher Haster 37:bf73ffd98cca 344 sys.stderr.write('Warning! mbed-os not found?\n')
Christopher Haster 15:a6b1f4e65bf4 345 sys.exit(-1)
Christopher Haster 15:a6b1f4e65bf4 346
Christopher Haster 40:2446665dfdf8 347 repo = Repo.fromrepo()
Christopher Haster 40:2446665dfdf8 348
Christopher Haster 21:1a3f920b6f07 349 macros = []
Christopher Haster 15:a6b1f4e65bf4 350 if os.path.isfile('MACROS.txt'):
Christopher Haster 15:a6b1f4e65bf4 351 with open('MACROS.txt') as f:
Christopher Haster 15:a6b1f4e65bf4 352 macros = f.read().splitlines()
Christopher Haster 15:a6b1f4e65bf4 353
Christopher Haster 15:a6b1f4e65bf4 354 env = os.environ.copy()
Christopher Haster 15:a6b1f4e65bf4 355 env['PYTHONPATH'] = '.'
Christopher Haster 15:a6b1f4e65bf4 356 popen(['python', 'mbed-os/tools/make.py']
Christopher Haster 15:a6b1f4e65bf4 357 + list(chain.from_iterable(izip(repeat('-D'), macros)))
Christopher Haster 36:5f4546dde73b 358 + ['--source=%s' % repo.path,
Christopher Haster 36:5f4546dde73b 359 '--build=%s' % os.path.join(repo.path, '.build')]
Christopher Haster 15:a6b1f4e65bf4 360 + args,
Christopher Haster 15:a6b1f4e65bf4 361 env=env)
Christopher Haster 15:a6b1f4e65bf4 362
Christopher Haster 15:a6b1f4e65bf4 363 # Export command
Christopher Haster 15:a6b1f4e65bf4 364 @subcommand('export', 'args*',
Christopher Haster 15:a6b1f4e65bf4 365 help='generate project files')
Christopher Haster 15:a6b1f4e65bf4 366 def export(args):
Christopher Haster 15:a6b1f4e65bf4 367 if not os.path.isdir('mbed-os'):
Christopher Haster 37:bf73ffd98cca 368 sys.stderr.write('Warning! mbed-os not found?\n')
Christopher Haster 15:a6b1f4e65bf4 369 sys.exit(-1)
Christopher Haster 15:a6b1f4e65bf4 370
Christopher Haster 40:2446665dfdf8 371 repo = Repo.fromrepo()
Christopher Haster 40:2446665dfdf8 372
Christopher Haster 41:59e9d808ee05 373 macros = []
Christopher Haster 41:59e9d808ee05 374 if os.path.isfile('MACROS.txt'):
Christopher Haster 41:59e9d808ee05 375 with open('MACROS.txt') as f:
Christopher Haster 41:59e9d808ee05 376 macros = f.read().splitlines()
Christopher Haster 41:59e9d808ee05 377
Christopher Haster 18:1b4252106474 378 env = os.environ.copy()
Christopher Haster 18:1b4252106474 379 env['PYTHONPATH'] = '.'
Christopher Haster 15:a6b1f4e65bf4 380 popen(['python', 'mbed-os/tools/project.py',
Christopher Haster 36:5f4546dde73b 381 '--source=%s' % repo.path]
Christopher Haster 41:59e9d808ee05 382 + list(chain.from_iterable(izip(repeat('-D'), macros)))
Christopher Haster 18:1b4252106474 383 + args,
Christopher Haster 18:1b4252106474 384 env=env)
Christopher Haster 15:a6b1f4e65bf4 385
Christopher Haster 15:a6b1f4e65bf4 386 # Parse/run command
Christopher Haster 15:a6b1f4e65bf4 387 args, remainder = parser.parse_known_args()
Christopher Haster 15:a6b1f4e65bf4 388 status = args.command(args)
Christopher Haster 15:a6b1f4e65bf4 389 sys.exit(status or 0)
Christopher Haster 15:a6b1f4e65bf4 390