Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
mac_app.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2015 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import argparse
7import os
8import errno
9import subprocess
10import sys
11
12PLUTIL = ['/usr/bin/env', 'xcrun', 'plutil']
13
14IBTOOL = [
15 '/usr/bin/env',
16 'xcrun',
17 'ibtool',
18]
19
20
22 try:
23 os.makedirs(path)
24 except OSError as exc:
25 if exc.errno == errno.EEXIST and os.path.isdir(path):
26 return 0
27 else:
28 return -1
29
30 return 0
31
32
34 output_plist_file = os.path.abspath(os.path.join(args.output, 'Info.plist'))
35 return subprocess.check_call(PLUTIL + [
36 '-convert',
37 'binary1',
38 '-o',
39 output_plist_file,
40 '--',
41 args.input,
42 ])
43
44
45def ProcessNIB(args):
46 output_nib_file = os.path.join(
47 os.path.abspath(args.output),
48 "%s.nib" % os.path.splitext(os.path.basename(args.input))[0])
49
50 return subprocess.check_call(IBTOOL + [
51 '--module',
52 args.module,
53 '--auto-activate-custom-fonts',
54 '--target-device',
55 'mac',
56 '--compile',
57 output_nib_file,
58 os.path.abspath(args.input),
59 ])
60
61
63 application_path = os.path.join(args.dir, args.name + ".app", "Contents")
64 return MakeDirectories(application_path)
65
66
67def Main():
68 parser = argparse.ArgumentParser(description='A script that aids in '
69 'the creation of an Mac application')
70
71 subparsers = parser.add_subparsers()
72
73 # Plist Parser
74
75 plist_parser = subparsers.add_parser('plist', help='Process the Info.plist')
76 plist_parser.set_defaults(func=ProcessInfoPlist)
77
78 plist_parser.add_argument('-i', dest='input', help='The input plist path')
79 plist_parser.add_argument('-o', dest='output', help='The output plist dir')
80
81 # NIB Parser
82
83 plist_parser = subparsers.add_parser('nib', help='Process a NIB file')
84 plist_parser.set_defaults(func=ProcessNIB)
85
86 plist_parser.add_argument('-i', dest='input', help='The input nib path')
87 plist_parser.add_argument('-o', dest='output', help='The output nib dir')
88 plist_parser.add_argument('-m', dest='module', help='The module name')
89
90 # Directory Structure Parser
91
92 dir_struct_parser = subparsers.add_parser(
93 'structure', help='Creates the directory of an Mac application')
94
95 dir_struct_parser.set_defaults(func=GenerateProjectStructure)
96
97 dir_struct_parser.add_argument('-d', dest='dir', help='Out directory')
98 dir_struct_parser.add_argument('-n', dest='name', help='App name')
99
100 # Engage!
101
102 args = parser.parse_args()
103
104 return args.func(args)
105
106
107if __name__ == '__main__':
108 sys.exit(Main())
ProcessNIB(args)
Definition mac_app.py:45
GenerateProjectStructure(args)
Definition mac_app.py:62
ProcessInfoPlist(args)
Definition mac_app.py:33
Main()
Definition mac_app.py:67
MakeDirectories(path)
Definition mac_app.py:21