Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import argparse, glob, sys, os, datetime, time, subprocess
  2.  
  3. parser = argparse.ArgumentParser()
  4. parser.add_argument("src_path", metavar="path", type=str,
  5. help="Path to files to be merged; enclose in quotes, accepts * as wildcard for directories or filenames")
  6.  
  7. args = parser.parse_args()
  8. files = glob.glob(args.src_path)
  9.  
  10. def toDate(timestamp):
  11. return datetime.datetime.fromtimestamp(timestamp)
  12.  
  13. def toTouchFormat(timestamp):
  14. date = datetime.datetime.fromtimestamp(timestamp)
  15. return date.strftime("%y%m%d0000")
  16.  
  17. if not files:
  18. print('File does not exist: ' + args.src_path, file=sys.stderr)
  19. for file in files:
  20. print('File exists: ' + file)
  21. # path = Path(file)
  22. #last_modified = path.stat().st_mtime
  23. last_modified = int(os.stat(file).st_mtime)
  24. #created = path.stat().created
  25. created = int(os.stat(file).st_ctime)
  26. birthed = int(os.stat(file).st_birthtime)
  27. print('File birthed ' + str(toDate(birthed)))
  28. print('File created ' + str(toDate(created)))
  29. print('File modified ' + str(toDate(last_modified)))
  30.  
  31. if birthed >= last_modified:
  32. print('would modify')
  33. program = 'touch -t ' + str(toTouchFormat(last_modified)) + ' ' + file
  34. print(program)
  35. process = subprocess.Popen(program.split(), stdout=subprocess.PIPE)
  36. output, error = process.communicate()
  37. print(output)
  38. print(error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement