Created
June 30, 2013 22:25
-
-
Save danielcarr/5897233 to your computer and use it in GitHub Desktop.
This script was used for a very specific purpose once off in a project, and has no real re-usability value, but is retained here for posterity. I needed to move the "Go Pro!" button (reminding the user to upgrade to payed version) from the end of my menus to the beginning, so they would be more visible. The menu structure is determined by an App…
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/bin/env python | |
def move_gopro_in_file(filename): | |
file = open(filename) | |
lines = file.readlines() | |
file.close() | |
gopro = lines[-3] | |
from string import whitespace | |
if 'gopro' not in gopro.lower(): | |
return "GOPRO out of position in", filename | |
if "<array>" not in lines[3].lower() or lines[4] in whitespace: | |
return "Nowhere to move to. lines 3 and 4 are", lines[3] + '\n' + lines[4] | |
lines.remove(gopro) | |
lines.insert(4, gopro) | |
file = open(filename, 'w') | |
file.writelines(lines) | |
file.close() | |
return filename | |
if __name__ == "__main__": | |
import os | |
pwd = os.listdir('.') | |
failing_files = [] # add files here if they are known to be problematic (or already fixed) | |
for f in pwd: | |
if 'plist' in f and 'bubble' not in f and 'menu' not in f: | |
try: | |
done = move_gopro_in_file(f) | |
if done != f: | |
failing_files.append(f) | |
else: print "moved gopro in", done # give feedback | |
except Exception: failing_files.append(f) | |
if len(failing_files) > 0: | |
from pprint import pprint | |
print "FAILED:" | |
pprint(failing_files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment