Browse Source

[LPC1768] Add error-handling to upload script, update autobuild.py (#10802)

Bob Kuhn 6 years ago
parent
commit
6dfbb39f83
2 changed files with 98 additions and 59 deletions
  1. 31
    13
      Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py
  2. 67
    46
      buildroot/share/atom/auto_build.py

+ 31
- 13
Marlin/src/HAL/HAL_LPC1768/upload_extra_script.py View File

34
     #
34
     #
35
 
35
 
36
     import os
36
     import os
37
+    upload_disk = 'Disk not found'
37
     target_file_found = False
38
     target_file_found = False
38
     target_drive_found = False
39
     target_drive_found = False
39
     for drive in drives:
40
     for drive in drives:
66
       env.Replace(
67
       env.Replace(
67
           UPLOAD_PORT = upload_disk
68
           UPLOAD_PORT = upload_disk
68
       )
69
       )
69
-
70
+      print 'upload disk: ' , upload_disk
71
+    else:
72
+       print '\nUnable to find destination disk.  File must be copied manually. \n'
70
 
73
 
71
 
74
 
72
 if current_OS == 'Linux':
75
 if current_OS == 'Linux':
76
     #
79
     #
77
 
80
 
78
     import os
81
     import os
82
+    upload_disk = 'Disk not found'
79
     target_file_found = False
83
     target_file_found = False
80
     target_drive_found = False
84
     target_drive_found = False
81
     medias = os.listdir('/media')  #
85
     medias = os.listdir('/media')  #
85
         target_drive_found = True
89
         target_drive_found = True
86
         upload_disk = '/media/' + media + '/' + target_drive + '/'
90
         upload_disk = '/media/' + media + '/' + target_drive + '/'
87
       for drive in drives:
91
       for drive in drives:
88
-        files = os.listdir('/media/' + media + '/' + drive )  #
89
-        if target_filename in files:
90
-          if target_file_found == False:
91
-            upload_disk = '/media/' + media + '/' + drive + '/'
92
-            target_file_found = True
92
+        try:
93
+          files = os.listdir('/media/' + media + '/' + drive )
94
+        except:
95
+          continue
96
+        else:
97
+          if target_filename in files:
98
+            if target_file_found == False:
99
+              upload_disk = '/media/' + media + '/' + drive + '/'
100
+              target_file_found = True
93
 
101
 
94
     #
102
     #
95
     # set upload_port to drive if found
103
     # set upload_port to drive if found
101
         UPLOAD_FLAGS = "-P$UPLOAD_PORT",
109
         UPLOAD_FLAGS = "-P$UPLOAD_PORT",
102
         UPLOAD_PORT = upload_disk
110
         UPLOAD_PORT = upload_disk
103
       )
111
       )
112
+      print 'upload disk: ' , upload_disk
113
+    else:
114
+       print '\nUnable to find destination disk.  File must be copied manually. \n'
104
 
115
 
105
 
116
 
106
 if current_OS == 'Darwin':  # MAC
117
 if current_OS == 'Darwin':  # MAC
110
     #
121
     #
111
 
122
 
112
     import os
123
     import os
124
+    upload_disk = 'Disk not found'
113
     drives = os.listdir('/Volumes')  #  human readable names
125
     drives = os.listdir('/Volumes')  #  human readable names
114
     target_file_found = False
126
     target_file_found = False
115
     target_drive_found = False
127
     target_drive_found = False
116
     if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
128
     if target_drive in drives and target_file_found == False:  # set upload if not found target file yet
117
       target_drive_found = True
129
       target_drive_found = True
118
-      upload_disk = '/Volumes/' + drive + '/'
130
+      upload_disk = '/Volumes/' + target_drive + '/'
119
     for drive in drives:
131
     for drive in drives:
120
-      target_file_found = True
121
-      filenames = os.listdir('/Volumes/' + drive + '/')
122
-      if target_filename in filenames:
123
-        if target_file_found == False:
124
-          upload_disk = '/Volumes/' + drive + '/'
125
-        target_file_found = True
132
+      try:
133
+        filenames = os.listdir('/Volumes/' + drive + '/')   # will get an error if the drive is protected
134
+      except:
135
+        continue
136
+      else:
137
+        if target_filename in filenames:
138
+          if target_file_found == False:
139
+            upload_disk = '/Volumes/' + drive + '/'
140
+          target_file_found = True
126
     #
141
     #
127
     # set upload_port to drive if found
142
     # set upload_port to drive if found
128
     #
143
     #
132
       env.Replace(
147
       env.Replace(
133
           UPLOAD_PORT = upload_disk
148
           UPLOAD_PORT = upload_disk
134
       )
149
       )
150
+      print '\nupload disk: ' , upload_disk, '\n'
151
+    else:
152
+       print '\nUnable to find destination disk.  File must be copied manually. \n'

+ 67
- 46
buildroot/share/atom/auto_build.py View File

204
        #get line and column numbers
204
        #get line and column numbers
205
         line_num = 1
205
         line_num = 1
206
         column_num = 1
206
         column_num = 1
207
-        line_start = path.find(':')
207
+        line_start = path.find(':', 2)                  # use 2 here so don't eat Windows full path
208
         column_start = path.find(':', line_start + 1)
208
         column_start = path.find(':', line_start + 1)
209
         if column_start == -1:
209
         if column_start == -1:
210
           column_start = len(path)
210
           column_start = len(path)
218
         if not(column_start == column_end):
218
         if not(column_start == column_end):
219
           column_num = path[ column_start + 1 : column_end]
219
           column_num = path[ column_start + 1 : column_end]
220
           if column_num == '':
220
           if column_num == '':
221
-            column_num = 1
221
+            column_num = 0
222
 
222
 
223
+        index_end = path.find(',')
224
+        if 0 <= index_end:
225
+            path = path[ : index_end]  # delete comma and anything after
226
+        index_end = path.find(':', 2)
227
+        if 0 <= index_end:
228
+            path = path[ : path.find(':', 2)]  # delete the line number and anything after
223
 
229
 
224
-        path = path[ : path.find(':')]  # delete the line number and anything after
225
         path = path.replace('\\','/')
230
         path = path.replace('\\','/')
226
 
231
 
227
-      # resolve as many '../' as we can
228
-        while 0 <= path.find('../'):
229
-          end =  path.find('../') - 1
230
-          start = path.find('/')
231
-          while 0 <= path.find('/',start) and end > path.find('/',start):
232
-            start = path.find('/',start) + 1
233
-          path = path[0:start] + path[end + 4: ]
234
-
235
-        # this is an alternative to the above - it just deletes the '../' section
236
-        # start_temp = path.find('../')
237
-        # while 0 <= path.find('../',start_temp):
238
-        #   start = path.find('../',start_temp)
239
-        #   start_temp = start  + 1
240
-        # if 0 <= start:
241
-        #   path = path[start + 2 : ]
242
-
243
-
244
-        start = path.find('/')
245
-        if not(0 == start):            # make sure path starts with '/'
246
-          while 0 == path.find(' '):    # eat any spaces at the beginning
247
-            path = path[ 1 : ]
248
-          path = '/' + path
232
+        if 1 == path.find(':') and current_OS == 'Windows':
233
+          return path, line_num, column_num                    # found a full path - no need for further processing
234
+        elif 0 == path.find('/') and (current_OS == 'Linux' or current_OS == 'Darwin'):
235
+          return path, line_num, column_num                    # found a full path - no need for further processing
249
 
236
 
250
-        if current_OS == 'Windows':
251
-          search_path = path.replace('/', '\\')  # os.walk uses '\' in Windows
252
         else:
237
         else:
253
-          search_path = path
254
-
255
-        start_path = os.path.abspath('')
256
 
238
 
257
-    # search project directory for the selection
258
-        found = False
259
-        full_path = ''
260
-        for root, directories, filenames in os.walk(start_path):
261
-          for filename in filenames:
262
-                  if  0 <= root.find('.git'):              # don't bother looking in this directory
263
-                    break
264
-                  full_path = os.path.join(root,filename)
265
-                  if 0 <= full_path.find(search_path):
266
-                    found = True
267
-                    break
268
-          if found:
269
-            break
239
+          # resolve as many '../' as we can
240
+            while 0 <= path.find('../'):
241
+              end =  path.find('../') - 1
242
+              start = path.find('/')
243
+              while 0 <= path.find('/',start) and end > path.find('/',start):
244
+                start = path.find('/',start) + 1
245
+              path = path[0:start] + path[end + 4: ]
246
+
247
+            # this is an alternative to the above - it just deletes the '../' section
248
+            # start_temp = path.find('../')
249
+            # while 0 <= path.find('../',start_temp):
250
+            #   start = path.find('../',start_temp)
251
+            #   start_temp = start  + 1
252
+            # if 0 <= start:
253
+            #   path = path[start + 2 : ]
254
+
255
+
256
+            start = path.find('/')
257
+            if not(0 == start):            # make sure path starts with '/'
258
+              while 0 == path.find(' '):    # eat any spaces at the beginning
259
+                path = path[ 1 : ]
260
+              path = '/' + path
261
+
262
+            if current_OS == 'Windows':
263
+              search_path = path.replace('/', '\\')  # os.walk uses '\' in Windows
264
+            else:
265
+              search_path = path
266
+
267
+            start_path = os.path.abspath('')
268
+
269
+        # search project directory for the selection
270
+            found = False
271
+            full_path = ''
272
+            for root, directories, filenames in os.walk(start_path):
273
+              for filename in filenames:
274
+                      if  0 <= root.find('.git'):              # don't bother looking in this directory
275
+                        break
276
+                      full_path = os.path.join(root,filename)
277
+                      if 0 <= full_path.find(search_path):
278
+                        found = True
279
+                        break
280
+              if found:
281
+                break
270
 
282
 
271
-        return full_path, line_num, column_num
283
+            return full_path, line_num, column_num
272
 
284
 
273
 # end - resolve_path
285
 # end - resolve_path
274
 
286
 
324
         elif current_OS == 'Linux':
336
         elif current_OS == 'Linux':
325
 
337
 
326
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
338
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
339
+              index_end = command.find(',')
340
+              if 0 <= index_end:
341
+                  command = command[ : index_end]  # sometimes a comma magically appears, don't want it
327
               running_apps = subprocess.Popen('ps ax -o cmd', stdout=subprocess.PIPE, shell=True)
342
               running_apps = subprocess.Popen('ps ax -o cmd', stdout=subprocess.PIPE, shell=True)
328
               (output, err) = running_apps.communicate()
343
               (output, err) = running_apps.communicate()
329
               temp = output.split('\n')
344
               temp = output.split('\n')
336
                   return False , ''
351
                   return False , ''
337
 
352
 
338
               (success_sublime, editor_path_sublime) = find_editor_linux('sublime_text',temp)
353
               (success_sublime, editor_path_sublime) = find_editor_linux('sublime_text',temp)
339
-              (success_atom, editor_path_atom) = find_editor+linux('atom',temp)
354
+              (success_atom, editor_path_atom) = find_editor_linux('atom',temp)
340
 
355
 
341
               if success_sublime:
356
               if success_sublime:
342
                   subprocess.Popen([editor_path_sublime, command])
357
                   subprocess.Popen([editor_path_sublime, command])
350
         elif current_OS == 'Darwin':  # MAC
365
         elif current_OS == 'Darwin':  # MAC
351
 
366
 
352
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
367
               command = file_path  + ':' + str(line_num) + ':' + str(column_num)
368
+              index_end = command.find(',')
369
+              if 0 <= index_end:
370
+                  command = command[ : index_end]  # sometimes a comma magically appears, don't want it
353
               running_apps = subprocess.Popen('ps axwww -o command', stdout=subprocess.PIPE, shell=True)
371
               running_apps = subprocess.Popen('ps axwww -o command', stdout=subprocess.PIPE, shell=True)
354
               (output, err) = running_apps.communicate()
372
               (output, err) = running_apps.communicate()
355
               temp = output.split('\n')
373
               temp = output.split('\n')
424
         date_last = 0.0
442
         date_last = 0.0
425
         DIR__pioenvs = os.listdir('.pioenvs')
443
         DIR__pioenvs = os.listdir('.pioenvs')
426
         for name in DIR__pioenvs:
444
         for name in DIR__pioenvs:
445
+          if 0 <= name.find('.') or 0 <= name.find('-'):   # skip files in listing
446
+            continue
427
           DIR_temp = os.listdir('.pioenvs/' + name)
447
           DIR_temp = os.listdir('.pioenvs/' + name)
428
           for names_temp in DIR_temp:
448
           for names_temp in DIR_temp:
449
+
429
             if 0 == names_temp.find('firmware.'):
450
             if 0 == names_temp.find('firmware.'):
430
               date_temp = os.path.getmtime('.pioenvs/' + name + '/' + names_temp)
451
               date_temp = os.path.getmtime('.pioenvs/' + name + '/' + names_temp)
431
               if date_temp > date_last:
452
               if date_temp > date_last:
941
         Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
962
         Text.__init__(self, self.frame, borderwidth=3, relief="sunken")
942
         self.config(tabs=(400,))  # configure Text widget tab stops
963
         self.config(tabs=(400,))  # configure Text widget tab stops
943
         self.config(background = 'black', foreground = 'white', font= ("consolas", 12), wrap = 'word', undo = 'True')
964
         self.config(background = 'black', foreground = 'white', font= ("consolas", 12), wrap = 'word', undo = 'True')
944
-        self.config(height  = 24, width = 120)
965
+        self.config(height  = 24, width = 100)
945
         self.config(insertbackground = 'pale green')  # keyboard insertion point
966
         self.config(insertbackground = 'pale green')  # keyboard insertion point
946
         self.pack(side='left', fill='both', expand=True)
967
         self.pack(side='left', fill='both', expand=True)
947
 
968
 

Loading…
Cancel
Save