Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import re
- import subprocess
- import sys
- remove_local1 = "rm -f /tmp/morphlines.conf"
- process = subprocess.Popen(remove_local1.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
- hdfs_move_from_hdfs = "hdfs dfs -getmerge /tmp/oracle/metadata/columns /tmp/col.txt"
- hdfs_move_to_hdfs = "hdfs dfs -moveFromLocal /tmp/morphlines_oracle.conf /tmp/oracle/"
- #hdfs_move_from_hdfs = "hdfs dfs -getmerge " + \
- # str(sys.argv[1]) + " /tmp/col.txt"
- #hdfs_move_to_hdfs = "hdfs dfs -moveFromLocal /tmp/new_morphlines.conf " + \
- # str(sys.argv[2])
- #hdfs_move_from_hdfs_morphlines = "hdfs dfs -get " + \
- # str(sys.argv[3]) + " /tmp/morphlines.txt"
- hdfs_move_from_hdfs_morphlines = "hdfs dfs -get /user/admin/scripts/morphlines_oracle.conf /tmp/morphlines.conf"
- remove_local = "rm -f /tmp/col.txt"
- process = subprocess.Popen(hdfs_move_from_hdfs.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
- process = subprocess.Popen(hdfs_move_from_hdfs_morphlines.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
- f = open('/tmp/col.txt', 'r')
- n = f.read()
- b = n.split()
- f.close()
- if 'database_ip' not in b:
- b.append('database_ip')
- if 'database_name' not in b:
- b.append('database_name')
- if 'id' not in b:
- b.append('id')
- if 'table_name' not in b:
- b.append('table_name')
- c = sorted(b)
- p = []
- for word in c:
- line = ' ' + word + ' : /' + word
- p.append(line)
- big_line = '\n'.join(p)
- morph = open('/tmp/morphlines.conf', 'r+')
- morph_readed_file = morph.read()
- find_peace = re.findall(r'paths : {\n([\S\s]*?)\n.*}', morph_readed_file)
- new_morph = re.sub(find_peace[0], big_line, morph_readed_file)
- new_file = open('/tmp/morphlines_oracle.conf', 'w+')
- new_file.write(new_morph)
- new_file.close()
- process = subprocess.Popen(hdfs_move_to_hdfs.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
- process = subprocess.Popen(remove_local.split(), stdout=subprocess.PIPE)
- output, error = process.communicate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement