[package] Fixed potential dereference of nullptr
[platform/core/api/webapi-plugins.git] / tools / generate_manifest.py
1 # Copyright (c) 2013 Intel Corporation. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import sys, os, re, errno
6
7 spec = sys.argv[1]
8 origin = sys.argv[2]
9
10 if len(sys.argv) != 8:
11     print 'Invalid arguments'
12     sys.exit(errno.EINVAL)
13
14 if not os.path.isfile(spec) or not os.path.isfile(origin):
15     print 'No such spec(%s) or input xml(%s) file' % (spec, origin)
16     sys.exit(errno.ENOENT)
17
18 spec = file(spec).read()
19 version = re.search('(?<=Version:).*', spec).group(0).strip()
20 package_name = re.search('(?<=%define '+sys.argv[3]+').*', spec).group(0).strip()
21
22 template = file(origin).read().replace('@PACKAGE_VERSION@', version)
23 template = template.replace('@PACKAGE_NAME@', package_name)
24 template = template.replace('@APP_ID@', sys.argv[4])
25 template = template.replace('@PACKAGE_EXEC@', sys.argv[5])
26 template = template.replace('@PACKAGE_LABEL@', sys.argv[6])
27
28 output = open(sys.argv[7], 'w')
29 output.write(template)
30 output.close()