-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathXcodeProject.py
More file actions
65 lines (48 loc) · 2.15 KB
/
Copy pathXcodeProject.py
File metadata and controls
65 lines (48 loc) · 2.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
import shutil
import datetime
from pbxproj.pbxextensions import *
class XcodeProject(PBXGenericObject, ProjectFiles, ProjectFlags, ProjectGroups):
"""
Top level class, handles the project CRUD operations, new, load, save, delete. Also, exposes methods to manipulate
the project's content, add/remove files, add/remove libraries/frameworks, query sections. For more advanced
operations, underlying objects are exposed that can be manipulated using said objects.
"""
def __init__(self, tree=None, path=None):
super(XcodeProject, self).__init__(parent=None)
if path is None:
path = os.path.join(os.getcwd(), 'project.pbxproj')
self._pbxproj_path = os.path.abspath(path)
self._source_root = os.path.abspath(os.path.join(os.path.split(path)[0], '..'))
# initialize the structure using the given tree
self.parse(tree)
def save(self, path=None):
if path is None:
path = self._pbxproj_path
f = open(path, 'w')
f.write(self.__repr__())
f.close()
def backup(self):
backup_name = "%s_%s.backup" % (self._pbxproj_path, datetime.datetime.now().strftime('%d%m%y-%H%M%S'))
shutil.copy2(self._pbxproj_path, backup_name)
return backup_name
def __repr__(self):
return u'// !$*UTF8*$!\n' + super(XcodeProject, self).__repr__()
def get_ids(self):
return self.objects.get_keys()
def get_build_phases_by_name(self, phase_name):
return self.objects.get_objects_in_section(phase_name)
def get_build_files_for_file(self, file_id):
return [build_file for build_file in self.objects.get_objects_in_section(u'PBXBuildFile')
if build_file.fileRef == file_id]
def get_target_by_name(self, name):
targets = self.objects.get_targets(name)
if targets.__len__() > 0:
return targets[0]
return None
def get_object(self, object_id):
return self.objects[object_id]
@classmethod
def load(cls, path):
import openstep_parser as osp
tree = osp.OpenStepDecoder.ParseFromFile(open(path, 'r'))
return XcodeProject(tree, path)