def fetch(remote_file, local_tmp_file, local_file, diff_tool):
cmd = 'scp %s %s' % (remote_file, local_tmp_file)
print(cmd)
os.system(cmd)
with open(local_tmp_file) as f:
txt = f.read()
ntxt = re.sub('Table of Contents.+markdown-toc.go\)', '[tableofcontent]', txt, flags=re.S)
with open(local_tmp_file, 'w') as f:
f.write(ntxt)
cmd = 'diff ' + local_tmp_file + ' ' + local_file
o = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if o.stdout.read().strip(): # if diff empty, file are the same
cmd = diff_tool + ' ' + local_tmp_file + ' ' + local_file
o = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
o.communicate()
o.wait()
else:
print('The files are the same')
# main
评论列表
文章目录