Created
September 19, 2015 08:48
-
-
Save vishvendra01/9829e42730f4a2f1dcb9 to your computer and use it in GitHub Desktop.
python script to rename br given android slices
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 | |
import os | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
def parse_nautilus_environment(): | |
result = { | |
'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS' : [], | |
'NAUTILUS_SCRIPT_SELECTED_URIS' : [], | |
'NAUTILUS_SCRIPT_CURRENT_URI' : [], | |
'NAUTILUS_SCRIPT_WINDOW_GEOMETRY' : [] | |
} | |
for i in result.keys(): | |
if os.environ.has_key(i): | |
result[i] = os.environ[i].split(':') | |
else: | |
result[i] = [] | |
logging.debug(result) | |
return result | |
def get_file_list(): | |
result = parse_nautilus_environment() | |
file_list = result['NAUTILUS_SCRIPT_SELECTED_FILE_PATHS']; | |
logging.debug("file_list:"+str(file_list)) | |
return file_list | |
def batch_rename(): | |
logging.debug("batch rename calling") | |
file_list = get_file_list() | |
file_list = file_list[0].split("\n") | |
main_file = "" | |
for x in file_list: | |
if (os.path.isfile(x)): | |
logging.debug(x) | |
if "@2x" not in x and "@3x" not in x: | |
main_file = x | |
break | |
else: | |
logging.debug("not a file") | |
logging.debug(main_file) | |
if main_file != "": | |
for x in file_list: | |
if (os.path.isfile(x)): | |
rename_file(x, main_file) | |
def rename_file(x, main_tag): | |
main_tag = main_tag[:len(main_tag)-4] | |
if ("@2x" in x): | |
tmp = x | |
tmp = main_tag+"@2x.png" | |
os.rename(x, tmp) | |
logging.debug("rename@2x:"+x) | |
elif ("@3x" in x): | |
tmp = x | |
tmp = main_tag+"@3x.png" | |
os.rename(x, tmp) | |
logging.debug("rename@3x:"+x) | |
if __name__ == "__main__": | |
logging.debug("start") | |
batch_rename() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment