-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-krita-bundle.py
executable file
·91 lines (79 loc) · 3.28 KB
/
create-krita-bundle.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
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from os.path import join, basename, isdir, isfile, expanduser
import shutil
import hashlib
from fnmatch import fnmatch
from glob import glob
from zipfile import ZipFile, ZIP_STORED
#from xml.sax.saxutils import escape as xmlescape
from lxml import etree
from lxml.builder import ElementMaker
try:
import ConfigParser as configparser
except ImportError:
try:
import configparser
except ImportError:
raise ImportError("Neither ConfigParser nor configparser module not found")
from bundle import Meta, Bundle
class Config(configparser.ConfigParser):
SECTION = "Bundle"
def __init__(self, filename=None):
configparser.ConfigParser.__init__(self)
self._filename = filename
if filename is not None:
self.read(filename)
def ask(self, option, default=None, config_option=None):
if self._filename is None:
t = " [{}]: ".format(default) if default is not None else ": "
r = raw_input(option + t)
if not r:
return default
else:
return r.decode('utf-8')
else:
if config_option is not None:
option = config_option
if self.has_option(self.SECTION, option):
return self.get(self.SECTION, option).decode('utf-8')
else:
return default
if __name__ == "__main__":
if len(sys.argv) == 2:
cfgfile = sys.argv[1]
else:
cfgfile = None
config = Config(cfgfile)
meta = Meta()
author = meta.author = config.ask("Author")
meta.description = config.ask("Description")
meta.initial_creator = config.ask("Initial creator", author)
meta.creator = config.ask("Creator", author)
meta.date = config.ask("Date")
meta.email = config.ask("Email")
meta.website = config.ask("Website")
meta.license = config.ask("License")
zipname = config.ask("Bundle file name")
brushdir = config.ask("Brushes directory", "brushes")
brushmask = config.ask("Brush files mask", "*.gbr;*.gih;*.png")
patdir = config.ask("Patterns directory", "patterns")
patmask = config.ask("Pattern files mask", "*.pat")
presetsdir = config.ask("Presets directory", "paintoppresets")
presetmask = config.ask("Preset files mask", "*.kpp")
skip_bad = config.ask("Skip presets with broken references", default=False, config_option="Skip bad presets")
skip_unused_brushes = config.ask("Skip unused brushes", default=False)
autopopulate = config.ask("Automatically add resources from directory", default=None, config_option="Auto add resources")
if autopopulate is not None:
autopopulate = autopopulate.split(";")
autopopulate = map(expanduser, autopopulate)
autopopulate = sum(map(glob, autopopulate), [])
preview = config.ask("Preview", "preview.png")
bundle = Bundle()
bundle.prepare(brushdir, brushmask, presetsdir, presetmask, patdir, patmask)
ok = bundle.check(skip_bad=skip_bad, resourcedir=autopopulate, skip_unused_brushes=skip_unused_brushes)
if not ok:
print("Bundle contains references to resources outside the bundle. You probably need to put required resources to the bundle itself.")
bundle.create(zipname, meta, preview)