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
Diff: neo.py
- Revision:
- 70:e6f7587c6562
- Parent:
- 69:eb600c35d6ac
- Child:
- 71:ddc08f2d5697
diff -r eb600c35d6ac -r e6f7587c6562 neo.py --- a/neo.py Wed Mar 30 20:23:51 2016 -0500 +++ b/neo.py Fri Apr 01 14:46:49 2016 +0100 @@ -18,13 +18,24 @@ parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() +def message(msg): + return "["+os.path.basename(sys.argv[0])+"] "+msg+"\n" + def log(msg): - sys.stderr.write("---\n"+msg+"\n") + sys.stderr.write(message(msg)) + +def action(msg): + sys.stderr.write("---\n"+message(msg)) def error(msg, code): - sys.stderr.write("---\nERROR: "+msg+"\n---\n") + sys.stderr.write("---\n["+os.path.basename(sys.argv[0])+" ERROR] "+msg+"\n---\n") sys.exit(code) - + +def repo_or_die(): + repo = Repo.fromrepo() + if repo.scm is None: + error("Current folder is not a repository", -1) + def subcommand(name, *args, **kwargs): def subcommand(command): subparser = subparsers.add_parser(name, **kwargs) @@ -47,18 +58,13 @@ return command return subcommand -def repo_or_die(): - repo = Repo.fromrepo() - if repo.scm is None: - error("Current folder is not a repository", -1) - # Process execution class ProcessException(Exception): pass def popen(command, stdin=None, **kwargs): # print for debugging - print ' '.join(command) + log(' '.join(command)) proc = subprocess.Popen(command, **kwargs) if proc.wait() != 0: @@ -104,15 +110,15 @@ name = 'hg' def clone(url, name=None, hash=None): - log("Cloning "+name+" from "+url) + action("Cloning "+name+" from "+url) popen([hg_cmd, 'clone', url, name] + (['-u', hash] if hash else [])) def add(file): - log("Adding "+file) + action("Adding "+file) popen([hg_cmd, 'add', file]) def remove(file): - log("Removing "+file) + action("Removing "+file) popen([hg_cmd, 'rm', '-f', file]) try: os.remove(file) @@ -123,11 +129,11 @@ popen([hg_cmd, 'commit']) def push(): - log("Pushing to remote repository") + action("Pushing to remote repository") popen([hg_cmd, 'push']) def pull(hash=None): - log("Pulling from remote repository") + action("Pulling from remote repository") popen([hg_cmd, 'pull']) popen([hg_cmd, 'update'] + (['-r', hash] if hash else [])) @@ -176,29 +182,29 @@ name = 'git' def clone(url, name=None, hash=None): - log("Cloning "+name+" from "+url) + action("Cloning "+name+" from "+url) popen([git_cmd, 'clone', url, name]) if hash: with cd(name): popen([git_cmd, 'checkout', '-q', hash]) def add(file): - log("Adding "+file) + action("Adding "+file) popen([git_cmd, 'add', file]) def remove(file): - log("Removing "+file) + action("Removing "+file) popen([git_cmd, 'rm', '-f', file]) def commit(): popen([git_cmd, 'commit', '-a']) def push(): - log("Pushing to remote repository") + action("Pushing to remote repository") popen([git_cmd, 'push', '--all']) def pull(hash=None): - log("Pulling from remote repository") + action("Pulling from remote repository") popen([git_cmd, 'fetch', 'origin']) popen([git_cmd, 'merge'] + ([hash] if hash else [])) @@ -395,7 +401,7 @@ dirty = repo.scm.dirty() if dirty: - log('Uncommitted changes in %s (%s)' % (repo.name, repo.path)) + action('Uncommitted changes in %s (%s)' % (repo.name, repo.path)) raw_input('Press enter to commit and push: ') repo.scm.commit()