Changed to parse specifically in GameData, to speed things up a bit. In master
Changed to parse specifically in GameData, to speed things up a bit. In
0.21, this should be pretty safe.

--- a/KSP_PartParser.py
+++ b/KSP_PartParser.py
@@ -10,6 +10,7 @@
 from KSPP_Config import Config

 from collections import OrderedDict

 import os, glob

+from sys import stderr

 

 def printCSV(parts):

 	csv_columns = OrderedDict({o.__name__: [o.HumanName] for o in Component.__subclasses__() if o is not MultiValueComponent})

@@ -110,7 +111,7 @@
 	import argparse

 	

 	parser = argparse.ArgumentParser(description='Parses a KSP install for part definitions.')

-	parser.add_argument('KSP_DIR', metavar='KSP_DIR', type=str, nargs='?', help='The KSP Directory to be parsed')

+	parser.add_argument('KSP_DIR', metavar='KSP_DIR', type=str, nargs='?', help='The KSP Directory to be parsed.  If this value is not provided, we will attempt to run on the current directory.')

 # 	parser.add_argument('-k', '--ksp-dir', metavar='DIR', type=str, help='Path to the KSP main directory.')

 # 	parser.add_argument('-r', '--resource-file', metavar='FILE', type=str, help='The ResourcesGeneric.cfg file to be used.')

 	parser.add_argument('-c', '--csv', action='store_true', help='Creates CSV output for all parsed part files.')

@@ -118,64 +119,31 @@
 	

 	args = parser.parse_args()

 	

-#  	files = args.files

-#  	

-#  	globfiles = []

-#  	remove_indexes = []

-#  	preloadParts = False

-#  	for PartFile in files:

-#  		if PartFile.count('*') > 0:

-#  				from glob import glob

-#  				globfiles += glob(PartFile)

-#  				remove_indexes.append(PartFile)

-#  		_, ext = os.path.splitext(PartFile)

-#  		if ext == '.craft' and not preloadParts:

-#  			preloadParts = True

-#  	for idx in remove_indexes:

-#  		files.remove(idx)

-#  	files += globfiles

-#  	

-#  	if args.ksp_dir is not None:

-#  		Config()['KSPDir'] = args.ksp_dir

-#  	else:

-#  		partdir, _ = os.path.split(files[0])

-#  		Config()['partsDir'] = partdir

-#  		Config()['KSPDir'] = os.sep.join((Config()['partsDir'], '..', '..'))

-#  	

-#  	if args.parts_dir is not None:

-#  		Config()['partsDir'] = args.parts_dir

-#  	

-#  	if args.resource_file is not None:

-#  		Config()['resourceFile'] = args.resource_file

-#  	else:

-#  		Config()['resourceFile'] = os.sep.join((Config()['KSPDir'], 'Resources', 'ResourcesGeneric.cfg'))

-#  	

-#  	Resource.createFromFile(Config()['resourceFile'])

-#  	

-#  	_, ext = os.path.splitext(PartFile)

-#  		# Let's parse some parts.

-#  	

-#  	if preloadParts:

-#  		from glob import glob

-#  		preloadFiles = glob(os.sep.join((Config()['partsDir'], '*', 'part.cfg')))

-#  		for PartFile in preloadFiles:

-#  			Part.createFromFile(PartFile, 1)

-	

 	if args.KSP_DIR is not None:

 		Config()['KSPDir'] = args.KSP_DIR

 	elif os.path.isfile("KSP.exe"):

 		Config()['KSPDir'] = "."

+	else:

+		stderr.write("Could not find KSP.exe and you did not provide a directory.  Please specify the directory of your KSP installation or run the script from inside your KSP root directory.")

+		exit(2)

 	

 	Config()['KSPDir'] = Config()['KSPDir'].rstrip(os.sep)

 	

 	Config()['GameDataDir'] = Config()['KSPDir'] + os.sep + "GameData"

 	

-	PartFiles = FindPartCfgs(Config()['KSPDir'])

+	PartFiles = FindPartCfgs(Config()['GameDataDir'])

 	

-	ResourceFiles = FindResourceCfgs(Config()['KSPDir'])

+	ResourceFiles = FindResourceCfgs(Config()['GameDataDir'])

 	

 	for ResourceFile in ResourceFiles:

-		Resource.createFromFile(ResourceFile)

+		try:

+			Resource.createFromFile(ResourceFile)

+		except IOError as e:

+			if e.errno == 13:

+				stderr.write("Skipping file {0}: {1}".format(e.filename, e.strerror))

+				continue

+			else:

+				raise e

 	

 	results = []

 	for PartFile in PartFiles:

@@ -187,7 +155,14 @@
 		elif ext == '.craft':

 			cls = Craft

 		

-		result = cls.createFromFile(PartFile)

+		try:

+			result = cls.createFromFile(PartFile)

+		except IOError as e:

+			if e.errno == 13:

+				stderr.write("Skipping file {0}: {1}".format(e.filename, e.strerror))

+				continue

+			else:

+				raise e

 		

 		results.append(result)