scorpion1453

bsd Renewal Make Quest

4 posts in this topic

I don't see the reason why you would do that, but it's fine, here's the python version if someone wants it.

import os
import subprocess

os.chdir(os.path.dirname(os.path.realpath(__file__)))

QC_ROOT_PATH = '.'
QC_EXTENSION_LIST = ('.lua', '.quest')
QC_COMMAND_STRING = './qc {filePath}'
QC_LOG_DICT = {'ok' : 0, 'error' : 0}

for root, dir, files in os.walk(QC_ROOT_PATH):
	for fileName in files:
		if fileName.endswith(QC_EXTENSION_LIST):
			hasCompiled = subprocess.call(QC_COMMAND_STRING.format(filePath='{}/{}'.format(root, fileName)), shell=True) == 0
			QC_LOG_DICT['ok' if hasCompiled else 'error'] += 1

print ('All quests are compiled, succeeded: {}, failed: {}.'.format(*QC_LOG_DICT.values()))
  • Like 5

Share this post


Link to post
Share on other sites
13 hours ago, Morpheus™ said:

Could somebody write on quest_list?

Not tested, i'm not at home.

What's new:

  • You can use comment sections in locale_list, helps you to identify much faster the quests.
  • Two methods of reading, if you enable QC_READ_FILE_FROM_LIST, all of the quests from locale_list will be compiled, if you enable QC_READ_ALL, all of the quests file from specific directory (folders/sub-folders) will be compiled.

How-To-Use:

  • python make.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
__author__  = "VegaS"
__date__    = "2019-12-11"
__version__ = "0.0.1"

import os
import subprocess

os.chdir(os.path.dirname(os.path.realpath(__file__)))

QC_READ_FILE_FROM_LIST = 0
QC_READ_ALL = 1

"""
# QC_READ_FILE_FROM_LIST
# Read the locale_list with all quest/lua files.
"""
# The file with all quest file names.
QC_FILE_NAME = 'locale_list'

"""
# QC_READ_ALL
# Find all of the quest/lua files from root directory
"""
# Directory path of searching quest file names
QC_ROOT_PATH = '.'
# File extensions to be search
QC_EXTENSION_LIST = ('.lua', '.quest')

"""
# General configuration
"""
# Command of quest compiler
QC_COMMAND_STRING = './qc {}'
# Comment string
QC_COMMENT_CHARACTER = '#'
# Default state
QC_READ_STATE = QC_READ_FILE_FROM_LIST

def find_quest_files(type):
	"""
	Generate all of the file names by specific type.
	:param type: int
	:return: generator
	"""
	if type == QC_READ_FILE_FROM_LIST:
		with open(QC_FILE_NAME, 'r') as file:
			for fileName in file.readlines():
				if fileName.strip():
					yield fileName
	elif type == QC_READ_ALL:
		for root, dirs, files in os.walk(QC_ROOT_PATH):
			for fileName in files:
				if fileName.endswith(QC_EXTENSION_LIST):
					yield "{}/{}".format(root, fileName)

def strip_quest_file_name(fileName):
	"""
	Strip file name, ignore the commented sections.
	:param fileName: string
	:return: string
	"""
	fileName = fileName.strip()
	if QC_COMMENT_CHARACTER in fileName:
		fileName = fileName.split(QC_COMMENT_CHARACTER)[0].strip()
	return fileName

def main():
	QC_LOG_DICT = {'ok': 0, 'error': 0}
	for fileName in find_quest_files(QC_READ_STATE):
		fileName = strip_quest_file_name(fileName)

		hasCompiled = subprocess.call(QC_COMMAND_STRING.format(fileName, shell=True)) == 0
		QC_LOG_DICT['ok' if hasCompiled else 'error'] += 1

	print ('All quests are compiled, succeeded: {}, failed: {}.'.format(*QC_LOG_DICT.values()))

if __name__ == "__main__":
	main()

 

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.