Reformat ALL the source!
[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 def createBundle():
45     try:
46         os.makedirs(CONTENTS_DIR + "MacOS")
47         os.makedirs(CONTENTS_DIR + "Resources")
48     except:
49         pass
50
51 def copyFiles(exeFile, iconFile):
52     os.system("cp %s %sMacOs/%s" % (exeFile, CONTENTS_DIR.replace(' ', '\ '), BUNDLE_NAME.replace(' ', '\ ')))
53     os.system("cp %s/%s %s/Resources" % (SOURCE_DIR, iconFile, CONTENTS_DIR.replace(' ', '\ ')))
54
55 def createPlist(bundleName, iconFile, bundleVersion):
56     templateFile = file(SOURCE_DIR + "/scripts/build/Info.plist", 'r')
57     template = templateFile.read()
58     templateFile.close()
59
60     plistFile = file(CONTENTS_DIR + "Info.plist", 'w')
61     plistFile.write(template % {"BUNDLE_NAME" : bundleName,
62                                 "ICON_FILE" : iconFile[iconFile.rfind("/")+1:],
63                                 "BUNDLE_VERSION" : bundleVersion})
64     plistFile.close()
65
66 if __name__ == "__main__":
67     createBundle()
68     createPlist(BUNDLE_NAME, ICON_FILE, BUNDLE_VERSION)
69     copyFiles(EXE_NAME, ICON_FILE)
70     pass