| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #!/usr/bin/python
- # Copyright (c) 2013 Daniele Bartolini, Michele Rossi
- # Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
- #
- # Permission is hereby granted, free of charge, to any person
- # obtaining a copy of this software and associated documentation
- # files (the "Software"), to deal in the Software without
- # restriction, including without limitation the rights to use,
- # copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the
- # Software is furnished to do so, subject to the following
- # conditions:
- #
- # The above copyright notice and this permission notice shall be
- # included in all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- # OTHER DEALINGS IN THE SOFTWARE.
- import sys
- import os
- import shutil
- from pycrown import Repository
- from pycrown import Compiler
- PERFECT_SEED_FILE = "seed.ini"
- GAME_LIBRARY_FILE = "libgame.so"
- # Helper for compiling resources
- class CompilerHelper:
- def __init__(self, root_path, platform_name):
- self.m_root_path = root_path
- # Define destination path name
- dest = os.path.dirname(root_path) + "/" + os.path.basename(root_path) + "_" + platform_name
- self.m_dest_path = os.path.normpath(dest)
- # Repository needs a root path
- self.m_repository = Repository.Repository(root_path)
- self.m_compiler = Compiler.Compiler(self.m_repository, self.m_dest_path)
- # Returns the root path where the resources are read from
- def root_path(self):
- return self.m_root_path
- # Returns the destination folder where the compiled resources
- # will be put
- def dest_path(self):
- return self.m_dest_path
- # Creates the destination folder
- def create_dest_folder(self):
- if not os.path.exists(self.m_dest_path):
- os.makedirs(self.m_dest_path)
- # Write the perfect seed into the destination folder
- def write_perfect_seed(self):
- seed_file_name = self.dest_path() + "/" + PERFECT_SEED_FILE
- seed_file_name = os.path.normpath(seed_file_name)
- file = open(seed_file_name, "w")
- file.write(str(self.m_compiler.perfect_seed()))
- file.close()
- # Compiles the resources into the destination folder
- def compile(self):
- # Scan the repository
- print("Scanning folder:", self.m_repository.root_path())
- self.m_repository.scan()
- print("Resources:", len(self.m_repository.all_resources()))
- # Create the output folder
- print("Creating destination folder:", self.dest_path())
- self.create_dest_folder()
- print("Compiling resources...")
- self.m_compiler.compile_all()
- print("Writing perfect seed...")
- self.write_perfect_seed()
- print("Done.")
- #------------------------------------------------------------------------------
- def main():
- root_path = ""
- if (len(sys.argv) != 3):
- print("Usage: resource-compiler <root-path> <platform-name>")
- sys.exit(-1)
- root_path = sys.argv[1];
- platform_name = sys.argv[2];
- root_path = os.path.abspath(root_path)
- if not os.path.exists(root_path):
- print("The path does not exist.")
- sys.exit(-1)
- if (os.path.islink(root_path)):
- print("The path is a symbolic link.")
- sys.exit(-1)
- if not os.path.isdir(root_path):
- print("The path has to be a directory.")
- sys.exit(-1)
- helper = CompilerHelper(root_path, platform_name)
- helper.compile()
- main()
|