-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenamerMaterialDesign.py
79 lines (67 loc) · 3.18 KB
/
RenamerMaterialDesign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""
RenamerMaterialDesign.py - Renaming your Android assets the easy way.
usage: python RenamerMaterialDesign.py [-h] -p PATH -f FILENAME [-d DESTINATION]
"""
import argparse
import os
import sys
if __name__ == '__main__':
print "RenamerMaterialDesign.py - Rename your Android assets the easy way."
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--path", help="The Assets path.", required=True,
dest="path")
parser.add_argument("-f", "--filename", help="Asset new filename pattern.",
required=True, dest="filename")
parser.add_argument("-d", "--destination", help="Asset new path", required=False,
dest="destination")
args = parser.parse_args()
if args.path and args.filename:
path = os.path.abspath(args.path) + '/'
destination_path = os.getcwd() + '/'
if not os.path.isdir(path):
print "ERROR: Can't find path: " + path
sys.exit(-1)
if not os.access(path, os.W_OK):
print "ERROR: " + path + " is not writable."
sys.exit(-1)
if args.destination is not None:
if not os.path.isdir(args.destination):
print "ERROR: Can't find destination path: " + path
sys.exit(-1)
if not os.access(args.destination, os.W_OK):
print "ERROR: " + args.destination + " is not writable."
sys.exit(-1)
destination_path = os.path.abspath(args.destination) + '/'
size = {
'ldpi': args.filename + '@0.75x.',
'drawable-ldpi': args.filename + '@0.75x.',
'drawable-ldrtl-ldpi': args.filename + '[email protected].',
'mdpi': args.filename + '.',
'drawable-mdpi': args.filename + '.',
'drawable-ldrtl-mdpi': args.filename + '-ldrtl.',
'hdpi': args.filename + '@1.5x.',
'drawable-hdpi': args.filename + '@1.5x.',
'drawable-ldrtl-hdpi': args.filename + '[email protected].',
'xhdpi': args.filename + '@2x.',
'drawable-xhdpi': args.filename + '@2x.',
'drawable-ldrtl-xhdpi': args.filename + '-ldrtl@2x.',
'xxhdpi': args.filename + '@3x.',
'drawable-xxhdpi': args.filename + '@3x.',
'drawable-ldrtl-xxhdpi': args.filename + '-ldrtl@3x.',
'xxxhdpi': args.filename + '@4x.',
'drawable-xxxhdpi': args.filename + '@4x.',
'drawable-ldrtl-xxxhdpi': args.filename + '-ldrtl@4x.'
}
print 'We are looking the directory from: ' + path # Selected path
print 'We are gonna put the files in this location: ' + destination_path # Selected destination
for directory in os.listdir(path):
if directory[0] == '.' or directory not in size:
continue
print directory # Current directory
print size[directory]
for asset in os.listdir(path + directory):
name = asset.split('.')
os.rename(path + directory + '/' + asset,
destination_path + size[directory] + name[1])
sys.exit(0) # Everything run OK