Merge pull request #132 from mamarley/md5corecertfix
[quassel.git] / scripts / build / macosx_makebundle.py
1 #!/usr/bin/python
2 # -*- coding: iso-8859-1 -*-
3
4 ################################################################################
5 #                                                                              #
6 # 2008 June 27th by Marcus 'EgS' Eggenberger <egs@quassel-irc.org>             #
7 #                                                                              #
8 # The author disclaims copyright to this source code.                          #
9 # This Python Script is in the PUBLIC DOMAIN.                                  #
10 #                                                                              #
11 ################################################################################
12
13 # ==============================
14 #  Imports
15 # ==============================
16 import os
17 import os.path
18 import sys
19 import commands
20
21 # ==============================
22 #  Constants
23 # ==============================
24 if len(sys.argv) < 2:
25     sys.exit(1)
26
27 SOURCE_DIR = sys.argv[1]
28
29 if len(sys.argv) < 4:
30     BUNDLE_NAME = "Quassel Client"
31     EXE_NAME = "quasselclient"
32 else:
33     EXE_NAME = sys.argv[3]
34     BUNDLE_NAME = sys.argv[2]
35
36 # make the dir of the exe the target dir
37 if(os.path.dirname(EXE_NAME)):
38     CONTENTS_DIR = os.path.dirname(EXE_NAME) + "/"
39 CONTENTS_DIR += BUNDLE_NAME + ".app/Contents/"
40
41 BUNDLE_VERSION = commands.getoutput("git --git-dir=" + SOURCE_DIR + "/.git/ describe")
42 ICON_FILE = "pics/quassel.icns"
43
44
45 def createBundle():
46     try:
47         os.makedirs(CONTENTS_DIR + "MacOS")
48         os.makedirs(CONTENTS_DIR + "Resources")
49     except:
50         pass
51
52
53 def copyFiles(exeFile, iconFile):
54     os.system("cp %s %sMacOs/%s" % (exeFile, CONTENTS_DIR.replace(' ', '\ '), BUNDLE_NAME.replace(' ', '\ ')))
55     os.system("cp %s/%s %s/Resources" % (SOURCE_DIR, iconFile, CONTENTS_DIR.replace(' ', '\ ')))
56
57
58 def createPlist(bundleName, iconFile, bundleVersion):
59     templateFile = file(SOURCE_DIR + "/scripts/build/Info.plist", 'r')
60     template = templateFile.read()
61     templateFile.close()
62
63     plistFile = file(CONTENTS_DIR + "Info.plist", 'w')
64     plistFile.write(template % {"BUNDLE_NAME": bundleName,
65                                 "ICON_FILE": iconFile[iconFile.rfind("/") + 1:],
66                                 "BUNDLE_VERSION": bundleVersion})
67     plistFile.close()
68
69 if __name__ == "__main__":
70     createBundle()
71     createPlist(BUNDLE_NAME, ICON_FILE, BUNDLE_VERSION)
72     copyFiles(EXE_NAME, ICON_FILE)