mptools 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mp-download +67 -0
  3. data/bin/mp-edit +83 -0
  4. metadata +5 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25dab59b2c886231d4e7522328652d4e5b87bca5
4
- data.tar.gz: 2c1a1c6c3459aa2c670d55331f1a8c105d36484d
3
+ metadata.gz: 58181d02c3ea1817b6cd546382c18ce5d67eb992
4
+ data.tar.gz: a7c5c42e94c7e10c3d6c315e9dab179dddc66450
5
5
  SHA512:
6
- metadata.gz: 81eac79562fd2bb456a440d889c5d088b6a1b78d8f3b8c2c0942081cb68f6970783b8a804404a28e16c73982819d67f3a92779ab186ff055a326e83c6eb0e85a
7
- data.tar.gz: 16e20aebdd1dd634e423212250ead79dccf4268224d8f267fcac4679b0ac6aee0df2315471d24e11f0a10542f404579feecb41b2abd6f59bb16f1a12efab8b50
6
+ metadata.gz: 6a4e2ee9f54c0da73c03765a43e29bb198e170b009df0ca611d70e213cde6602d32af9e304053451de57ed9d2baca4b67d74f2a2b137f1b65290e4ce2dc22157
7
+ data.tar.gz: b4a7e971efc42f7e87e45d36970b79f1508006a4fc1de30234b0f5f76800622fc5faa33ce184d1ed5283de0a03592d84551558dc4c693edb5903ad572e70ef83
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/ruby
2
+
3
+ ARGV.length!=3&&(puts("USAGE: mp-download <PORT> <MICROPYTHON FILENAME> <LOCAL FILENAME>");exit(1))
4
+ require 'serialport'
5
+ require 'timeout'
6
+
7
+ port, f_mc = ARGV
8
+
9
+ print "Opening serial port..."
10
+ begin
11
+ s = SerialPort.new(port)
12
+ rescue Errno::ENOENT
13
+ puts "FAIL"
14
+ puts "Could not open serial port to `#{port}`!"
15
+ exit(1)
16
+ end
17
+ puts "ok"
18
+ print "Interrupting program..."
19
+ s.write("\u0003\r\n\r\n")
20
+ ostr = ""
21
+ read_until_off = lambda do
22
+ loop do
23
+ begin
24
+ Timeout.timeout(0.1) do
25
+ ostr << s.read(1)
26
+ end
27
+ rescue Timeout::Error
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ read_until_off.call
34
+
35
+ unless ostr.reverse[0,4].reverse==">>> "
36
+ puts "FAIL"
37
+ puts "It is highly recommended that you plug out your"
38
+ puts "device and plug it back in and try running"
39
+ puts "this script again."
40
+ s.close
41
+ exit(1)
42
+ end
43
+ puts "ok"
44
+ print "Reading `#{f_mc}`..."
45
+ ostr.clear
46
+ s.write(%Q(open(#{f_mc.inspect},"r").read()\r\n))
47
+ ostr << s.read(1)
48
+ read_until_off.call
49
+ ostr = ostr.split("\r\n").drop(1).reverse.drop(1).reverse.join("\r\n")
50
+ if ostr[0,9] == "Traceback"
51
+ puts "FAIL"
52
+ puts "The file you want to download does not exist!"
53
+ exit(1)
54
+ end
55
+ puts "ok"
56
+
57
+ content = eval ostr.gsub("\\n","\n").gsub("\\t","\t").gsub("\\f","\f").gsub("\\r","\r")
58
+
59
+ print "Writing to `#{ARGV[2]}`..."
60
+ File.write(ARGV[2],content)
61
+ puts "ok"
62
+
63
+ print "Restarting..."
64
+ s.write("\u0004\r\n")
65
+ puts "ok"
66
+ s.close
67
+ puts "All done!"
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/ruby
2
+
3
+ ARGV.length!=2&&(puts("USAGE: mp-download <PORT> <MICROPYTHON FILENAME>");exit(1))
4
+ require 'serialport'
5
+ require 'timeout'
6
+
7
+ port, f_mc = ARGV
8
+
9
+ print "Opening serial port..."
10
+ begin
11
+ s = SerialPort.new(port)
12
+ rescue Errno::ENOENT
13
+ puts "FAIL"
14
+ puts "Could not open serial port to `#{port}`!"
15
+ exit(1)
16
+ end
17
+ puts "ok"
18
+ print "Interrupting program..."
19
+ s.write("\u0003\r\n\r\n")
20
+ ostr = ""
21
+ read_until_off = lambda do
22
+ loop do
23
+ begin
24
+ Timeout.timeout(0.1) do
25
+ ostr << s.read(1)
26
+ end
27
+ rescue Timeout::Error
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ read_until_off.call
34
+
35
+ unless ostr.reverse[0,4].reverse==">>> "
36
+ puts "FAIL"
37
+ puts "It is highly recommended that you plug out your"
38
+ puts "device and plug it back in and try running"
39
+ puts "this script again."
40
+ s.close
41
+ exit(1)
42
+ end
43
+ puts "ok"
44
+ print "Reading `#{f_mc}`..."
45
+ ostr.clear
46
+ s.write(%Q(open(#{f_mc.inspect},"r").read()\r\n))
47
+ ostr << s.read(1)
48
+ read_until_off.call
49
+ ostr = ostr.split("\r\n").drop(1).reverse.drop(1).reverse.join("\r\n")
50
+ if ostr[0,9] == "Traceback"
51
+ puts "FAIL"
52
+ puts "The file you want to edit does not exist!"
53
+ exit(1)
54
+ end
55
+
56
+ content = eval ostr.gsub("\\n","\n").gsub("\\t","\t").gsub("\\f","\f").gsub("\\r","\r")
57
+
58
+ fname = "/tmp/mptools-#{f_mc.gsub("/","-")}"
59
+ if File.exists?(fname)
60
+ puts "FAIL"
61
+ puts "The file is already being edited by another session!"
62
+ exit(1)
63
+ end
64
+
65
+ File.write(fname,content)
66
+ puts "ok"
67
+ ed = ENV["VISUAL"]||"nano"
68
+ system("#{ed} #{fname}")
69
+
70
+ f_content = File.read(fname)
71
+ print "Re-uploading `#{f_mc}`..."
72
+ s.write(%Q(f=open(#{f_mc.inspect},"rw+");f.write(#{f_content.inspect});f.close()\r\n\r\n))
73
+ ostr << s.read(1)
74
+ read_until_off.call
75
+ puts "ok"
76
+
77
+ File.delete(fname)
78
+
79
+ print "Restarting..."
80
+ s.write("\u0004\r\n")
81
+ puts "ok"
82
+ s.close
83
+ puts "All done!"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mptools
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sesshomariu
@@ -14,9 +14,13 @@ description: A variety of tools for your Micro Python
14
14
  email:
15
15
  executables:
16
16
  - mp-upload
17
+ - mp-download
18
+ - mp-edit
17
19
  extensions: []
18
20
  extra_rdoc_files: []
19
21
  files:
22
+ - bin/mp-download
23
+ - bin/mp-edit
20
24
  - bin/mp-upload
21
25
  homepage:
22
26
  licenses: []