transport 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. __doc__ = """
  3. (c) 2018 - 2021 data-transport
  4. steve@the-phi.com, The Phi Technology LLC
  5. https://dev.the-phi.com/git/steve/data-transport.git
  6. This program performs ETL between 9 supported data sources : Couchdb, Mongodb, Mysql, Mariadb, PostgreSQL, Netezza,Redshift, Sqlite, File
  7. LICENSE (MIT)
  8. Copyright 2016-2020, The Phi Technology LLC
  9. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12. Usage :
  13. transport --config <path-to-file.json> --procs <number-procs>
  14. @TODO: Create tables if they don't exist for relational databases
  15. example of configuration :
  16. 1. Move data from a folder to a data-store
  17. transport [--folder <path> ] --config <config.json> #-- assuming the configuration doesn't have folder
  18. transport --folder <path> --provider <postgresql|mongo|sqlite> --<database|db> <name> --table|doc <document_name>
  19. In this case the configuration should look like :
  20. {folder:..., target:{}}
  21. 2. Move data from one source to another
  22. transport --config <file.json>
  23. {source:{..},target:{..}} or [{source:{..},target:{..}},{source:{..},target:{..}}]
  24. """
  25. import pandas as pd
  26. import numpy as np
  27. import json
  28. import sys
  29. import transport
  30. import time
  31. from multiprocessing import Process
  32. SYS_ARGS = {}
  33. if len(sys.argv) > 1:
  34. N = len(sys.argv)
  35. for i in range(1,N):
  36. value = None
  37. if sys.argv[i].startswith('--'):
  38. key = sys.argv[i][2:] #.replace('-','')
  39. SYS_ARGS[key] = 1
  40. if i + 1 < N:
  41. value = sys.argv[i + 1] = sys.argv[i+1].strip()
  42. if key and value and not value.startswith('--'):
  43. SYS_ARGS[key] = value
  44. i += 2
  45. if __name__ == '__main__' :
  46. #
  47. # Load information from the file ...
  48. if 'help' in SYS_ARGS :
  49. print (__doc__)
  50. else:
  51. try:
  52. _info = json.loads(open(SYS_ARGS['config']).read())
  53. if 'index' in SYS_ARGS :
  54. _index = int(SYS_ARGS['index'])
  55. _info = [_item for _item in _info if _info.index(_item) == _index]
  56. pass
  57. procs = 1 if 'procs' not in SYS_ARGS else int(SYS_ARGS['procs'])
  58. jobs = transport.factory.instance(provider='etl',info=_info,procs=procs)
  59. while jobs :
  60. x = len(jobs)
  61. jobs = [_job for _job in jobs if _job.is_alive()]
  62. if x != len(jobs) :
  63. print ([len(jobs),'... jobs running'])
  64. time.sleep(1)
  65. except Exception as e:
  66. print (e)