Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import re
  4. import subprocess
  5. import sys
  6.  
  7. remove_local1 = "rm -f /tmp/morphlines.conf"
  8.  
  9. process = subprocess.Popen(remove_local1.split(), stdout=subprocess.PIPE)
  10. output, error = process.communicate()
  11.  
  12. hdfs_move_from_hdfs = "hdfs dfs -getmerge /tmp/oracle/metadata/columns /tmp/col.txt"
  13. hdfs_move_to_hdfs = "hdfs dfs -moveFromLocal /tmp/morphlines_oracle.conf /tmp/oracle/"
  14.  
  15.  
  16. #hdfs_move_from_hdfs = "hdfs dfs -getmerge " + \
  17. # str(sys.argv[1]) + " /tmp/col.txt"
  18.  
  19. #hdfs_move_to_hdfs = "hdfs dfs -moveFromLocal /tmp/new_morphlines.conf " + \
  20. # str(sys.argv[2])
  21.  
  22.  
  23.  
  24. #hdfs_move_from_hdfs_morphlines = "hdfs dfs -get " + \
  25. # str(sys.argv[3]) + " /tmp/morphlines.txt"
  26.  
  27.  
  28. hdfs_move_from_hdfs_morphlines = "hdfs dfs -get /user/admin/scripts/morphlines_oracle.conf /tmp/morphlines.conf"
  29.  
  30.  
  31.  
  32. remove_local = "rm -f /tmp/col.txt"
  33.  
  34. process = subprocess.Popen(hdfs_move_from_hdfs.split(), stdout=subprocess.PIPE)
  35. output, error = process.communicate()
  36.  
  37. process = subprocess.Popen(hdfs_move_from_hdfs_morphlines.split(), stdout=subprocess.PIPE)
  38. output, error = process.communicate()
  39.  
  40.  
  41. f = open('/tmp/col.txt', 'r')
  42. n = f.read()
  43. b = n.split()
  44. f.close()
  45.  
  46. if 'database_ip' not in b:
  47. b.append('database_ip')
  48.  
  49. if 'database_name' not in b:
  50. b.append('database_name')
  51.  
  52. if 'id' not in b:
  53. b.append('id')
  54.  
  55. if 'table_name' not in b:
  56. b.append('table_name')
  57.  
  58. c = sorted(b)
  59. p = []
  60. for word in c:
  61. line = ' ' + word + ' : /' + word
  62. p.append(line)
  63.  
  64. big_line = '\n'.join(p)
  65.  
  66. morph = open('/tmp/morphlines.conf', 'r+')
  67. morph_readed_file = morph.read()
  68.  
  69. find_peace = re.findall(r'paths : {\n([\S\s]*?)\n.*}', morph_readed_file)
  70.  
  71. new_morph = re.sub(find_peace[0], big_line, morph_readed_file)
  72.  
  73. new_file = open('/tmp/morphlines_oracle.conf', 'w+')
  74. new_file.write(new_morph)
  75. new_file.close()
  76.  
  77. process = subprocess.Popen(hdfs_move_to_hdfs.split(), stdout=subprocess.PIPE)
  78. output, error = process.communicate()
  79.  
  80. process = subprocess.Popen(remove_local.split(), stdout=subprocess.PIPE)
  81. output, error = process.communicate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement