diff --git a/.gitignore b/.gitignore index 0d20b64..9c4c81b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.pyc +dist/ +kbinxml.egg-info/ diff --git a/README.md b/README.md index 433b23a..d538ef8 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,7 @@ An encoder/decoder for Konami's binary XML format, used in some of their games. ### Setup: -`pip install bitarray lxml` - -Additionally for Python 2: -`pip install future` +`pip install .` ```python In [1]: from kbinxml import KBinXML @@ -17,4 +14,6 @@ Out[4]: b'\xa0B\x80\x7f\x00\x00\x00\x08\x0b\x04\xdfM9\xfe\xff\x00\x00\x00\x00\x1 In [5]: bin = KBinXML(Out[4]) In [6]: bin.to_text() Out[7]: u'\nHello, world!\n' -``` \ No newline at end of file +``` + +You can also use `kbinxml` from the commandline to convert files. \ No newline at end of file diff --git a/kbinxml/__init__.py b/kbinxml/__init__.py new file mode 100644 index 0000000..58e99d6 --- /dev/null +++ b/kbinxml/__init__.py @@ -0,0 +1 @@ +from .kbinxml import KBinXML, main diff --git a/bytebuffer.py b/kbinxml/bytebuffer.py similarity index 100% rename from bytebuffer.py rename to kbinxml/bytebuffer.py diff --git a/format_ids.py b/kbinxml/format_ids.py similarity index 100% rename from format_ids.py rename to kbinxml/format_ids.py diff --git a/kbinxml.py b/kbinxml/kbinxml.py similarity index 98% rename from kbinxml.py rename to kbinxml/kbinxml.py index da514b1..0abbeb5 100644 --- a/kbinxml.py +++ b/kbinxml/kbinxml.py @@ -7,9 +7,10 @@ import operator from io import BytesIO import lxml.etree as etree -from bytebuffer import ByteBuffer -from sixbit import pack_sixbit, unpack_sixbit -from format_ids import xml_formats, xml_types + +from .bytebuffer import ByteBuffer +from .sixbit import pack_sixbit, unpack_sixbit +from .format_ids import xml_formats, xml_types stdout = getattr(sys.stdout, 'buffer', sys.stdout) @@ -309,7 +310,7 @@ class KBinXML(): # because we need the 'real' root self.xml_doc = self.xml_doc[0] -if __name__ == '__main__': +def main(): if len(sys.argv) != 2: print('bin_xml.py file.[xml/bin]') exit() @@ -322,3 +323,6 @@ if __name__ == '__main__': stdout.write(xml.to_text().encode('utf-8')) else: stdout.write(xml.to_binary()) + +if __name__ == '__main__': + main() diff --git a/sixbit.py b/kbinxml/sixbit.py similarity index 100% rename from sixbit.py rename to kbinxml/sixbit.py diff --git a/test.py b/kbinxml/test.py similarity index 96% rename from test.py rename to kbinxml/test.py index 81ecbad..e5f13c1 100644 --- a/test.py +++ b/kbinxml/test.py @@ -1,4 +1,4 @@ -from kbinxml import KBinXML +from .kbinxml import KBinXML # python 2/3 cross compat from io import open diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3a63d4e --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup +import sys + + +requires = [ + 'bitarray', + 'lxml', +] +if sys.version_info < (3,0): + requires.append('future') + +setup( + name='kbinxml', + version='1.0', + entry_points = { + 'console_scripts': ['kbinxml=kbinxml:main'], + }, + packages=['kbinxml'], + url='https://github.com/mon/kbinxml/', + author='mon', + author_email='me@mon.im', + install_requires=requires +)