summaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-01 17:01:37 +0800
committerTat-Chee Wan (USM)2011-03-01 17:01:37 +0800
commita85e78c4532ad1e9d7c8282334280db5e700b7f0 (patch)
treecfcbf734bb146b8531304e912d91114e914ff831 /AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
parenteae3f8bdb3de377d5e303bffb84238f0d86beee2 (diff)
parent2234d3c1cae095a3a450e7c5bbf0c7b89bb6c346 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
Diffstat (limited to 'AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push')
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push47
1 files changed, 47 insertions, 0 deletions
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
new file mode 100644
index 0000000..395b38f
--- /dev/null
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/scripts/nxt_push
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# nxt_push program -- Push a file to a LEGO Mindstorms NXT brick
+# Copyright (C) 2006 Douglas P Lau
+# Copyright (C) 2010 rhn
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+import sys
+import nxt.locator
+from nxt.brick import FileWriter
+from nxt.error import FileNotFound
+from nxt.utils import parse_command_line_arguments
+
+def _write_file(b, fname, data):
+ w = FileWriter(b, fname, len(data))
+ print 'Pushing %s (%d bytes) ...' % (fname, w.size),
+ sys.stdout.flush()
+ w.write(data)
+ print 'wrote %d bytes' % len(data)
+ w.close()
+
+def write_file(b, fname):
+ f = open(fname)
+ data = f.read()
+ f.close()
+ try:
+ b.delete(fname)
+ print 'Overwriting %s on NXT' % fname
+ except FileNotFound:
+ pass
+ _write_file(b, fname, data)
+
+if __name__ == '__main__':
+ arguments, keyword_arguments = parse_command_line_arguments(sys.argv)
+
+ brick = nxt.locator.find_one_brick(keyword_arguments['host'])
+ for filename in arguments:
+ write_file(brick, filename)