Morpheus / Mbed OS mbed-Client-Morpheus-hg

Dependencies:   mbed-os

Committer:
Christopher Haster
Date:
Wed Mar 30 08:23:05 2016 -0500
Revision:
34:8d47baea4754
Parent:
32:81aa45b17e5a
Parent:
30:dcc9ff39aee3
Child:
35:ffcfa5ace437
Merged incoming changes

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 collections
Christopher Haster 15:a6b1f4e65bf4 10 import shutil
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 15:a6b1f4e65bf4 93 class Repo(object):
Christopher Haster 15:a6b1f4e65bf4 94 def __init__(self, path=None):
Christopher Haster 15:a6b1f4e65bf4 95 self.path = path or os.getcwd()
Christopher Haster 15:a6b1f4e65bf4 96 self.name = os.path.basename(self.path)
Christopher Haster 15:a6b1f4e65bf4 97 self.update()
Christopher Haster 15:a6b1f4e65bf4 98
Christopher Haster 15:a6b1f4e65bf4 99 @classmethod
Christopher Haster 15:a6b1f4e65bf4 100 def fromurl(cls, url, name=None):
Christopher Haster 15:a6b1f4e65bf4 101 repo = cls.__new__(cls)
Christopher Haster 22:599f5dc9c20e 102 url = url.strip()
Christopher Haster 15:a6b1f4e65bf4 103
Christopher Haster 15:a6b1f4e65bf4 104 m = re.match('^(.*/([+a-zA-Z0-9_-]+)/?)(?:#(.*))?$', url)
Christopher Haster 15:a6b1f4e65bf4 105 repo.repo = m.group(1)
Christopher Haster 15:a6b1f4e65bf4 106 repo.name = name or m.group(2)
Christopher Haster 15:a6b1f4e65bf4 107 repo.hash = m.group(3)
Christopher Haster 15:a6b1f4e65bf4 108
Christopher Haster 15:a6b1f4e65bf4 109 repo.path = os.path.join(os.getcwd(), repo.name)
Christopher Haster 15:a6b1f4e65bf4 110 return repo
Christopher Haster 15:a6b1f4e65bf4 111
Christopher Haster 15:a6b1f4e65bf4 112 @property
Christopher Haster 15:a6b1f4e65bf4 113 def lib(self):
Christopher Haster 15:a6b1f4e65bf4 114 return self.path + '.lib'
Christopher Haster 15:a6b1f4e65bf4 115
Christopher Haster 15:a6b1f4e65bf4 116 @property
Christopher Haster 15:a6b1f4e65bf4 117 def url(self):
Christopher Haster 15:a6b1f4e65bf4 118 if self.repo:
Christopher Haster 15:a6b1f4e65bf4 119 if self.hash:
Christopher Haster 15:a6b1f4e65bf4 120 return self.repo + '#' + self.hash
Christopher Haster 15:a6b1f4e65bf4 121 else:
Christopher Haster 15:a6b1f4e65bf4 122 return self.repo
Christopher Haster 15:a6b1f4e65bf4 123
Christopher Haster 15:a6b1f4e65bf4 124 def update(self):
Christopher Haster 15:a6b1f4e65bf4 125 if os.path.isdir(self.path):
Christopher Haster 15:a6b1f4e65bf4 126 self.type = self.gettype()
Christopher Haster 15:a6b1f4e65bf4 127 self.hash = self.gethash()
Christopher Haster 15:a6b1f4e65bf4 128
Christopher Haster 15:a6b1f4e65bf4 129 if os.path.isfile(self.lib):
Christopher Haster 15:a6b1f4e65bf4 130 with open(self.lib) as f:
Christopher Haster 15:a6b1f4e65bf4 131 temp = Repo.fromurl(f.read())
Christopher Haster 15:a6b1f4e65bf4 132 self.repo = temp.repo
Christopher Haster 15:a6b1f4e65bf4 133
Christopher Haster 15:a6b1f4e65bf4 134 def gettype(self):
Christopher Haster 15:a6b1f4e65bf4 135 for type, dir in [('hg', '.hg'), ('git', '.git')]:
Christopher Haster 15:a6b1f4e65bf4 136 if os.path.isdir(os.path.join(self.path, dir)):
Christopher Haster 15:a6b1f4e65bf4 137 return type
Christopher Haster 15:a6b1f4e65bf4 138
Christopher Haster 15:a6b1f4e65bf4 139 def gethash(self):
Christopher Haster 15:a6b1f4e65bf4 140 with cd(self.path):
Christopher Haster 15:a6b1f4e65bf4 141 if self.type == 'git':
Christopher Haster 15:a6b1f4e65bf4 142 return pquery(['git', 'rev-parse', '--short', 'HEAD']).strip()
Christopher Haster 15:a6b1f4e65bf4 143 elif self.type == 'hg':
Christopher Haster 24:b29dad301edd 144 return pquery(['hg', 'id', '-i']).strip().strip('+')
Christopher Haster 15:a6b1f4e65bf4 145
Christopher Haster 15:a6b1f4e65bf4 146 # Clone command
Christopher Haster 15:a6b1f4e65bf4 147 @subcommand('import', 'url', 'name?',
Christopher Haster 15:a6b1f4e65bf4 148 help='recursively import a repository')
Christopher Haster 15:a6b1f4e65bf4 149 def import_(url, name=None):
Christopher Haster 15:a6b1f4e65bf4 150 repo = Repo.fromurl(url, name)
Christopher Haster 15:a6b1f4e65bf4 151
Christopher Haster 15:a6b1f4e65bf4 152 for type in ['hg', 'git']:
Christopher Haster 15:a6b1f4e65bf4 153 try:
Christopher Haster 15:a6b1f4e65bf4 154 popen([type, 'clone', repo.repo, repo.path])
Christopher Haster 15:a6b1f4e65bf4 155 break
Christopher Haster 15:a6b1f4e65bf4 156 except:
Christopher Haster 15:a6b1f4e65bf4 157 pass
Christopher Haster 15:a6b1f4e65bf4 158
Christopher Haster 15:a6b1f4e65bf4 159 repo.type = repo.gettype()
Christopher Haster 15:a6b1f4e65bf4 160
Christopher Haster 15:a6b1f4e65bf4 161 if repo.hash:
Christopher Haster 15:a6b1f4e65bf4 162 with cd(repo.path):
Christopher Haster 15:a6b1f4e65bf4 163 popen([repo.type, 'checkout', repo.hash])
Christopher Haster 15:a6b1f4e65bf4 164
Christopher Haster 15:a6b1f4e65bf4 165 repo.update()
Christopher Haster 15:a6b1f4e65bf4 166
Christopher Haster 15:a6b1f4e65bf4 167 with cd(repo.path):
Christopher Haster 15:a6b1f4e65bf4 168 for url, lib in iterlibs():
Christopher Haster 15:a6b1f4e65bf4 169 import_(url, lib)
Christopher Haster 15:a6b1f4e65bf4 170
Christopher Haster 19:6ace1080b8bb 171 if (not os.path.isfile('mbed_settings.py') and
Christopher Haster 19:6ace1080b8bb 172 os.path.isfile('mbed-os/tools/settings.py')):
screamer 30:dcc9ff39aee3 173 shutil.copy('mbed-os/tools/default_settings.py', 'mbed_settings.py')
Christopher Haster 19:6ace1080b8bb 174
Christopher Haster 15:a6b1f4e65bf4 175 # Deploy command
Christopher Haster 15:a6b1f4e65bf4 176 @subcommand('deploy',
Christopher Haster 15:a6b1f4e65bf4 177 help='recursively import libraries in current directory')
Christopher Haster 15:a6b1f4e65bf4 178 def deploy():
Christopher Haster 15:a6b1f4e65bf4 179 for url, lib in iterlibs():
Christopher Haster 15:a6b1f4e65bf4 180 import_(url, lib)
Christopher Haster 15:a6b1f4e65bf4 181
Christopher Haster 15:a6b1f4e65bf4 182 # Install/uninstall command
Christopher Haster 15:a6b1f4e65bf4 183 @subcommand('add', 'url', 'name?',
Christopher Haster 15:a6b1f4e65bf4 184 help='add a library to the current repository')
Christopher Haster 15:a6b1f4e65bf4 185 def add(url, name):
Christopher Haster 15:a6b1f4e65bf4 186 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 187 repo = Repo.fromurl(url, name)
Christopher Haster 15:a6b1f4e65bf4 188
Christopher Haster 15:a6b1f4e65bf4 189 import_(url)
Christopher Haster 15:a6b1f4e65bf4 190
Christopher Haster 15:a6b1f4e65bf4 191 repo.update()
Christopher Haster 15:a6b1f4e65bf4 192 savelib(repo)
Christopher Haster 15:a6b1f4e65bf4 193
Christopher Haster 15:a6b1f4e65bf4 194 popen([cwd.type, 'add', repo.lib])
Christopher Haster 15:a6b1f4e65bf4 195
Christopher Haster 15:a6b1f4e65bf4 196 @subcommand('remove', 'library',
Christopher Haster 15:a6b1f4e65bf4 197 help='remove a library from the current repository folder')
Christopher Haster 15:a6b1f4e65bf4 198 def remove(library):
Christopher Haster 15:a6b1f4e65bf4 199 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 200 repo = Repo(library)
Christopher Haster 15:a6b1f4e65bf4 201
Christopher Haster 15:a6b1f4e65bf4 202 popen([cwd.type, 'rm', '-f', repo.lib])
Christopher Haster 15:a6b1f4e65bf4 203
Christopher Haster 16:b54f256e339e 204 try:
Christopher Haster 16:b54f256e339e 205 if cwd.type == 'hg':
Christopher Haster 16:b54f256e339e 206 os.remove(repo.lib)
Christopher Haster 16:b54f256e339e 207
Christopher Haster 16:b54f256e339e 208 shutil.rmtree(repo.path)
Christopher Haster 16:b54f256e339e 209 except OSError:
Christopher Haster 16:b54f256e339e 210 pass
Christopher Haster 15:a6b1f4e65bf4 211
Christopher Haster 15:a6b1f4e65bf4 212 # Publish command
Christopher Haster 15:a6b1f4e65bf4 213 @subcommand('publish',
Christopher Haster 15:a6b1f4e65bf4 214 help='recursively publish changes to remote repositories')
Christopher Haster 18:1b4252106474 215 def publish(always=True):
Christopher Haster 15:a6b1f4e65bf4 216 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 217
Christopher Haster 15:a6b1f4e65bf4 218 for url, lib in iterlibs():
Christopher Haster 15:a6b1f4e65bf4 219 if os.path.isdir(lib):
Christopher Haster 15:a6b1f4e65bf4 220 with cd(lib):
Christopher Haster 18:1b4252106474 221 publish(False)
Christopher Haster 15:a6b1f4e65bf4 222
Christopher Haster 17:1e487c450f06 223 synch()
Christopher Haster 17:1e487c450f06 224
Christopher Haster 17:1e487c450f06 225 if cwd.type == 'hg':
Christopher Haster 27:ac93c15efe97 226 modified = pquery(['hg', 'status', '-q'])
Christopher Haster 17:1e487c450f06 227 elif cwd.type == 'git':
Christopher Haster 17:1e487c450f06 228 modified = pquery(['git', 'diff', '--name-only', 'HEAD'])
Christopher Haster 17:1e487c450f06 229
Christopher Haster 17:1e487c450f06 230 if modified:
Christopher Haster 17:1e487c450f06 231 print cwd.path
Christopher Haster 17:1e487c450f06 232 print 'Uncommitted changes in %s' % cwd.name
Christopher Haster 24:b29dad301edd 233 raw_input('Press enter to commit and push ')
Christopher Haster 17:1e487c450f06 234
Christopher Haster 17:1e487c450f06 235 popen([cwd.type, 'commit'] + (['-a'] if cwd.type == 'git' else []))
Christopher Haster 18:1b4252106474 236
Christopher Haster 18:1b4252106474 237 if modified or always:
Christopher Haster 18:1b4252106474 238 try:
Christopher Haster 18:1b4252106474 239 popen([cwd.type, 'push'] + (['-a'] if cwd.type == 'git' else []))
Christopher Haster 18:1b4252106474 240 except ProcessException as e:
Christopher Haster 18:1b4252106474 241 sys.exit(e[0])
Christopher Haster 15:a6b1f4e65bf4 242
Christopher Haster 20:84d6e18cbc20 243 # Update command
Christopher Haster 20:84d6e18cbc20 244 @subcommand('update', 'ref?',
Christopher Haster 20:84d6e18cbc20 245 help='recursively updates libraries and current repository')
Christopher Haster 20:84d6e18cbc20 246 def update(ref=None):
Christopher Haster 20:84d6e18cbc20 247 cwd = Repo()
Christopher Haster 24:b29dad301edd 248
Christopher Haster 20:84d6e18cbc20 249 popen([cwd.type, 'pull'])
Christopher Haster 24:b29dad301edd 250 if cwd.type == 'hg':
Christopher Haster 24:b29dad301edd 251 popen(['hg', 'update'])
Christopher Haster 20:84d6e18cbc20 252
Christopher Haster 20:84d6e18cbc20 253 if ref:
Christopher Haster 20:84d6e18cbc20 254 popen([cwd.type, 'checkout', ref])
Christopher Haster 20:84d6e18cbc20 255
Christopher Haster 20:84d6e18cbc20 256 for url, lib in iterlibs():
Christopher Haster 20:84d6e18cbc20 257 repo = Repo.fromurl(url, lib)
Christopher Haster 20:84d6e18cbc20 258 if os.path.isdir(lib):
Christopher Haster 20:84d6e18cbc20 259 with cd(repo.path):
Christopher Haster 20:84d6e18cbc20 260 update(repo.hash)
Christopher Haster 20:84d6e18cbc20 261 else:
Christopher Haster 20:84d6e18cbc20 262 import_(url, lib)
Christopher Haster 20:84d6e18cbc20 263
Christopher Haster 15:a6b1f4e65bf4 264 # Synch command
Christopher Haster 15:a6b1f4e65bf4 265 @subcommand('synch',
Christopher Haster 15:a6b1f4e65bf4 266 help='synchronize lib files')
Christopher Haster 15:a6b1f4e65bf4 267 def synch():
Christopher Haster 15:a6b1f4e65bf4 268 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 269
Christopher Haster 15:a6b1f4e65bf4 270 for url, lib in iterlibs():
Christopher Haster 15:a6b1f4e65bf4 271 repo = Repo.fromurl(url, lib)
Christopher Haster 15:a6b1f4e65bf4 272 repo.update()
Christopher Haster 22:599f5dc9c20e 273 if url == repo.url:
Christopher Haster 15:a6b1f4e65bf4 274 continue
Christopher Haster 15:a6b1f4e65bf4 275
Christopher Haster 15:a6b1f4e65bf4 276 savelib(repo)
Christopher Haster 15:a6b1f4e65bf4 277
Christopher Haster 15:a6b1f4e65bf4 278 if cwd.type == 'git':
Christopher Haster 15:a6b1f4e65bf4 279 popen([cwd.type, 'add', repo.lib])
Christopher Haster 15:a6b1f4e65bf4 280
Christopher Haster 15:a6b1f4e65bf4 281 # Compile command
Christopher Haster 15:a6b1f4e65bf4 282 @subcommand('compile', 'args*',
Christopher Haster 15:a6b1f4e65bf4 283 help='compile project using workspace_tools')
Christopher Haster 15:a6b1f4e65bf4 284 def compile(args):
Christopher Haster 15:a6b1f4e65bf4 285 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 286
Christopher Haster 15:a6b1f4e65bf4 287 if not os.path.isdir('mbed-os'):
Christopher Haster 15:a6b1f4e65bf4 288 sys.stderr.write('Warning! mbed-os not found?')
Christopher Haster 15:a6b1f4e65bf4 289 sys.exit(-1)
Christopher Haster 15:a6b1f4e65bf4 290
Christopher Haster 21:1a3f920b6f07 291 macros = []
Christopher Haster 15:a6b1f4e65bf4 292 if os.path.isfile('MACROS.txt'):
Christopher Haster 15:a6b1f4e65bf4 293 with open('MACROS.txt') as f:
Christopher Haster 15:a6b1f4e65bf4 294 macros = f.read().splitlines()
Christopher Haster 15:a6b1f4e65bf4 295
Christopher Haster 15:a6b1f4e65bf4 296 env = os.environ.copy()
Christopher Haster 15:a6b1f4e65bf4 297 env['PYTHONPATH'] = '.'
Christopher Haster 15:a6b1f4e65bf4 298 popen(['python', 'mbed-os/tools/make.py']
Christopher Haster 15:a6b1f4e65bf4 299 + list(chain.from_iterable(izip(repeat('-D'), macros)))
Christopher Haster 15:a6b1f4e65bf4 300 + ['--source=%s' % cwd.path,
Christopher Haster 15:a6b1f4e65bf4 301 '--build=%s' % os.path.join(cwd.path, '.build')]
Christopher Haster 15:a6b1f4e65bf4 302 + args,
Christopher Haster 15:a6b1f4e65bf4 303 env=env)
Christopher Haster 15:a6b1f4e65bf4 304
Christopher Haster 15:a6b1f4e65bf4 305 # Export command
Christopher Haster 15:a6b1f4e65bf4 306 @subcommand('export', 'args*',
Christopher Haster 15:a6b1f4e65bf4 307 help='generate project files')
Christopher Haster 15:a6b1f4e65bf4 308 def export(args):
Christopher Haster 15:a6b1f4e65bf4 309 cwd = Repo()
Christopher Haster 15:a6b1f4e65bf4 310
Christopher Haster 15:a6b1f4e65bf4 311 if not os.path.isdir('mbed-os'):
Christopher Haster 15:a6b1f4e65bf4 312 sys.stderr.write('Warning! mbed-os not found?')
Christopher Haster 15:a6b1f4e65bf4 313 sys.exit(-1)
Christopher Haster 15:a6b1f4e65bf4 314
Christopher Haster 18:1b4252106474 315 env = os.environ.copy()
Christopher Haster 18:1b4252106474 316 env['PYTHONPATH'] = '.'
Christopher Haster 15:a6b1f4e65bf4 317 popen(['python', 'mbed-os/tools/project.py',
Christopher Haster 17:1e487c450f06 318 '--source=%s' % cwd.path]
Christopher Haster 18:1b4252106474 319 + args,
Christopher Haster 18:1b4252106474 320 env=env)
Christopher Haster 15:a6b1f4e65bf4 321
Christopher Haster 15:a6b1f4e65bf4 322 # Parse/run command
Christopher Haster 15:a6b1f4e65bf4 323 args, remainder = parser.parse_known_args()
Christopher Haster 15:a6b1f4e65bf4 324 status = args.command(args)
Christopher Haster 15:a6b1f4e65bf4 325 sys.exit(status or 0)
Christopher Haster 15:a6b1f4e65bf4 326