forked from jcs/endless
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinfo_plist.py
More file actions
executable file
·144 lines (114 loc) · 5.15 KB
/
info_plist.py
File metadata and controls
executable file
·144 lines (114 loc) · 5.15 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
#
# Copyright (c) 2017, Psiphon Inc.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import datetime
import plistlib
import sys
class CFBundleShortVersionString:
def __init__(self, version):
self.major, self.minor, self.patch = version.split('.')
def increment_major(self):
self.major = str(int(self.patch)+1)
def increment_minor(self):
self.minor = str(int(self.patch)+1)
def increment_patch(self):
self.patch = str(int(self.patch)+1)
def __str__(self):
return '.'.join([self.major, self.minor, self.patch])
class InfoPlist:
version_key = 'CFBundleVersion' # for internal use, development
short_version_key = 'CFBundleShortVersionString' # for release versions, app store
def __init__(self, plist_path, debug=False):
self.debug = debug
self.plist_path = plist_path
self.plist = plistlib.readPlist(self.plist_path)
self.version = int(self.plist[self.version_key])
self.short_version = CFBundleShortVersionString(self.plist[self.short_version_key])
def sync(self):
if self.plist[self.version_key] != str(self.version_key):
if self.debug:
print '{0} updated from {1} to {2}'.format(self.version_key, self.plist[self.version_key], self.version)
if self.plist[self.short_version_key] != str(self.short_version):
if self.debug:
print '{0} updated from {1} to {2}'.format(self.short_version_key,
self.plist[self.short_version_key],
self.short_version)
self.plist[self.version_key] = str(self.version)
self.plist[self.short_version_key] = str(self.short_version)
plistlib.writePlist(self.plist, self.plist_path)
def increment_for_release(self):
self.version += 1
self.short_version.increment_patch()
self.sync()
def increment_for_testflight(self):
self.version += 1
self.sync()
def release_version_string(self):
return '{0}'.format(self.short_version)
def testflight_version_string(self):
return '{0}'.format(self.version)
def human_readable_version_string(self):
return 'TestFlight version {0}; Release version {1}'.format(self.version, self.short_version)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
prog="info_plist",
)
parser.add_argument("-p",
"--plist",
help="Path to the Info.plist file in your Xcode project that you wish to increment",
required=True,
type=str)
parser.add_argument("-i",
"--increment_for",
choices=['release', 'testflight'],
help="Increment plist to the next logical version for the target distribution platform.",
required=False,
type=str)
parser.add_argument("-o",
"--output",
choices=['human_readable', 'short_version', 'version'],
default='human_readable',
help="Print the specified version string",
required=False,
type=str)
parser.add_argument("-d",
"--debug",
help="Specify that debug info should be printed to stdout",
required=False,
action='store_true')
args = parser.parse_args()
info_plist = InfoPlist(args.plist, args.debug)
if args.increment_for is not None:
if args.increment_for == 'release':
info_plist.increment_for_release()
elif args.increment_for == 'testflight':
info_plist.increment_for_testflight()
else:
sys.exit('Invalid distribution platform specified. Must be "release" or "testflight".')
if args.output is not None:
if args.output == 'version':
print info_plist.testflight_version_string()
elif args.output == 'short_version':
print info_plist.release_version_string()
elif args.output == 'human_readable':
print info_plist.human_readable_version_string()
else:
sys.exit('Invalid output specified. Must be "short_version" or "version".')
else:
print "[%s] Initialized as a library" % (datetime.datetime.now())