|
1 | 1 | __copyright__ = """ |
2 | 2 |
|
3 | | - Copyright 2022 Samapriya Roy |
| 3 | + Copyright 2023 Samapriya Roy |
4 | 4 |
|
5 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | you may not use this file except in compliance with the License. |
@@ -269,22 +269,15 @@ def tabup(dirc, uname, destination, x, y, overwrite=None): |
269 | 269 | if v.validate(asset_validate, schema) is False: |
270 | 270 | print(v.errors) |
271 | 271 | raise Exception |
272 | | - with open( |
273 | | - os.path.join(lp, "data.json"), "w" |
274 | | - ) as outfile: |
275 | | - json.dump(main_payload, outfile) |
| 272 | + request_id = ee.data.newTaskId()[0] |
276 | 273 | if overwrite is not None and overwrite.lower() in check_list: |
277 | | - output = subprocess.check_output( |
278 | | - f"earthengine upload table --manifest {os.path.join(lp, 'data.json')} -f", |
279 | | - shell=True |
280 | | - ) |
| 274 | + output = ee.data.startTableIngestion( |
| 275 | + request_id, main_payload, allow_overwrite=True) |
281 | 276 | else: |
282 | | - output = subprocess.check_output( |
283 | | - f"earthengine upload table --manifest {os.path.join(lp, 'data.json')}", |
284 | | - shell=True |
285 | | - ) |
| 277 | + output = ee.data.startTableIngestion( |
| 278 | + request_id, main_payload, allow_overwrite=False) |
286 | 279 | logging.info( |
287 | | - f"Ingesting {i+1} of {file_count} {str(os.path.basename(asset_full_path))} with Task Id: {output.decode('ascii').strip().split(' ')[-1]}" |
| 280 | + f"Ingesting {i+1} of {file_count} {str(os.path.basename(asset_full_path))} with Task Id: {output['id']} & status {output['started']}" |
288 | 281 | ) |
289 | 282 | elif base_ext == ".csv": |
290 | 283 | m = MultipartEncoder( |
@@ -337,17 +330,15 @@ def tabup(dirc, uname, destination, x, y, overwrite=None): |
337 | 330 | if v.validate(asset_validate, schema) is False: |
338 | 331 | print(v.errors) |
339 | 332 | raise Exception |
340 | | - with open( |
341 | | - os.path.join(lp, "data.json"), "w" |
342 | | - ) as outfile: |
343 | | - json.dump(main_payload, outfile) |
344 | | - manifest_file = os.path.join(lp, "data.json") |
345 | | - output = subprocess.check_output( |
346 | | - f"earthengine upload table --manifest {manifest_file}", |
347 | | - shell=True, |
348 | | - ) |
| 333 | + request_id = ee.data.newTaskId()[0] |
| 334 | + if overwrite is not None and overwrite.lower() in check_list: |
| 335 | + output = ee.data.startTableIngestion( |
| 336 | + request_id, main_payload, allow_overwrite=True) |
| 337 | + else: |
| 338 | + output = ee.data.startTableIngestion( |
| 339 | + request_id, main_payload, allow_overwrite=False) |
349 | 340 | logging.info( |
350 | | - f"Ingesting {i+1} of {file_count} {str(os.path.basename(asset_full_path))} with Task Id: {output.decode('ascii').strip().split(' ')[-1]}" |
| 341 | + f"Ingesting {i+1} of {file_count} {str(os.path.basename(asset_full_path))} with Task Id: {output['id']} & status {output['started']}" |
351 | 342 | ) |
352 | 343 | except Exception as error: |
353 | 344 | print(error) |
|
0 commit comments