Created
April 11, 2017 20:10
-
-
Save raymanfx/2ba0a51d4031ddf13d3b47b648446563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env python3 | |
import os | |
import stat | |
import sys | |
def main(): | |
argc = len(sys.argv) | |
if argc < 2: | |
print("[ERROR] invalid argument count, expected: " + str(2) | |
+ ", got: " + str(argc)) | |
sys.exit(1) | |
file = sys.argv[1] | |
# read from file | |
buf = None | |
with open(file, "r") as fp: | |
buf = fp.read() | |
if buf is None: | |
print("[ERROR] could not open file: " + file + " for reading") | |
sys.exit(1) | |
num_changes_performed = 0 | |
for line in buf.split('\n'): | |
if "delete mode" in line: | |
print("[INFO] deleted file: " + line) | |
continue | |
if "mode change" in line: | |
index = line.find("=>") | |
elements = line.split() | |
previous = elements[2] | |
following = elements[4] | |
file_path = elements[5] | |
print("[INFO] " + file_path + ": " + following + " => " + previous) | |
statbuf = os.stat(file_path) | |
mode = statbuf.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | |
os.chmod(file_path, mode) | |
num_changes_performed += 1 | |
print("[INFO] done, performed " + str(num_changes_performed) + " changes") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment