ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset
BatCountrySVN/emot_port/emot_port.py
Revision: 12
Committed: Tue Mar 24 10:06:43 2009 UTC (17 months, 2 weeks ago) by jeremye_bcsvn
File size: 3101 byte(s)
Log Message:
updated version of old emot_port.py
removed dependency on 4Suite, external plist tool
Line User Rev File contents
1 jeremye_bcsvn 12 #!/usr/bin/env python
2     # -*- coding: utf-8 -*-
3    
4     import sys, os, re, shutil
5     from plistlib import *
6    
7     usage = """
8     usage:
9     emot_port.py emoticons.AdiumEmoticonSet [emoticons.colloquyEmoticons]
10     """
11    
12     adiumBundlePath = "sa.AdiumEmoticonSet"
13     colloquyBundlePath = "sa.colloquyEmoticons"
14    
15     emoticonCSSCommonFrag = """
16     .emoticon:after {
17     vertical-align: -40%;
18     }
19     """
20    
21     emoticonCSSFragTmpl = """
22     .emoticon.%(safeName)s:after {
23     content: url("%(safeImage)s");
24     }
25     .emoticon.%(safeName)s samp {
26     display: none;
27     }
28     """
29    
30     def mkCSSSafeName(existingSafeNames, imgFile):
31     first = '_'.join(re.findall(r"[A-Za-z0-9]+", imgFile)).lower()
32     if first == '':
33     first = 'anon'
34     elif re.match(r"^\d+", first):
35     first = 'num_'
36     if first in existingSafeNames:
37     first += "_dup_"
38     i = 1
39     while (first + str(i) in existingSafeNames):
40     i += 1
41     first += str(i)
42     existingSafeNames.add(first)
43     return first
44    
45     def main():
46     if len(sys.argv) < 2 or len(sys.argv) > 3:
47     print usage
48     sys.exit(1)
49     adiumBundlePath = sys.argv[1]
50     if len(sys.argv) > 2:
51     colloquyBundlePath = sys.argv[2]
52     else:
53     colloquyBundlePath = os.path.splitext(adiumBundlePath)[0] + '.colloquyEmoticons'
54    
55     os.mkdir(colloquyBundlePath)
56     os.mkdir(os.path.join(colloquyBundlePath, 'Contents'))
57     os.mkdir(os.path.join(colloquyBundlePath, 'Contents', 'Resources'))
58     bundleName = os.path.splitext(os.path.split(colloquyBundlePath)[1])[0]
59     colloquyInfoPlist = {
60     'CFBundlePackageType':
61     'coEm',
62     'CFBundleName':
63     bundleName,
64     'CFBundleIdentifier':
65     'us.bat-country.emot-port.%s.AdiumEmoticonSet' % bundleName,
66     }
67     writePlist(colloquyInfoPlist, os.path.join(colloquyBundlePath, 'Contents', 'Info.plist'))
68     emoticonCSSF = open(os.path.join(colloquyBundlePath, 'Contents', 'Resources', 'emoticons.css'), 'w')
69     emoticonCSSF.write(emoticonCSSCommonFrag)
70    
71     adiumEmots = readPlist(os.path.join(adiumBundlePath, 'Emoticons.plist'))['Emoticons']
72     colloquyMenuPlist = []
73     colloquyEmoticonsPlist = {}
74     safeNames = set()
75     for image, props in adiumEmots.items():
76     basename, ext = os.path.splitext(image)
77     safeName = mkCSSSafeName(safeNames, basename)
78     safeImage = safeName + ext
79     emoticonCSSF.write(emoticonCSSFragTmpl % vars())
80     colloquyMenuPlist.append({
81     'image':
82     safeImage,
83     'name':
84     props['Name'],
85     'insert':
86     props['Equivalents'][0],
87     })
88     colloquyEmoticonsPlist[safeName] = props['Equivalents']
89     shutil.copyfile(
90     os.path.join(adiumBundlePath, image),
91     os.path.join(colloquyBundlePath, 'Contents', 'Resources', safeImage))
92    
93     emoticonCSSF.close()
94     writePlist(colloquyMenuPlist, os.path.join(colloquyBundlePath, 'Contents', 'Resources', 'menu.plist'))
95     writePlist(colloquyEmoticonsPlist, os.path.join(colloquyBundlePath, 'Contents', 'Resources', 'emoticons.plist'))
96    
97     if __name__ == '__main__':
98     main()
99    

Properties

Name Value
svn:executable *