-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
80 lines (64 loc) · 2.06 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import re
import mimetypes
from yapsy.PluginManager import PluginManager
from os import path
from PIL import Image
# Create the emote pack container
class EmotePack(object):
name = "Untitled Pack"
desc = ""
author = ""
version = ""
icon = ""
emotelist = []
class Emote(object):
filename = ""
filetype = ""
shortcuts = []
width = 0
height = 0
inputData = open(path.join("input", "theme"), 'r')
inputData = inputData.read()
# Instantiate and fill the pack metadata
InputPack = EmotePack()
try:
InputPack.name = re.findall(r"Name=(.*)", inputData)[-1]
except IndexError:
print "Couldn't find a name, skipping"
pass
try:
InputPack.desc = re.findall(r"Description=(.*)", inputData)[-1]
except IndexError:
print "Couldn't find a description, skipping"
pass
InputPack.desc += " converted by Kline Eto"
try:
InputPack.author = re.findall(r"Author=(.*)", inputData)[-1]
except IndexError:
print "Couldn't find an author, skipping"
pass
# Reopen the pack in line mode
inputFile = open(path.join("input", "theme"), 'r')
inputFile = inputFile.readlines()
# Fill the container with Emotes
for line in inputFile:
if line.startswith('!'):
line = line.replace('!', '') # Strip off the leading !
line = line.split() # Split into tokens
thisEmote = Emote()
thisEmote.filename = line[0] # Identify the file and its type, as required for some formats.
thisEmote.filetype = mimetypes.guess_type(line[0])[0]
thisEmote.shortcuts = line[1:]
try: # Dimensions are required for phpBB
im = Image.open(path.join("input", thisEmote.filename))
thisEmote.width, thisEmote.height = im.size
except IOError: # If the file doesn't exist, lets not package it, either
continue
InputPack.emotelist.append(thisEmote)
pm = PluginManager(
directories_list=["templates"],
plugin_info_ext="plug"
)
pm.collectPlugins()
for backend in pm.getAllPlugins():
backend.plugin_object.build(InputPack)