KSP_PartParser: Renamed from KSP_Parser.
KSP_PartParser: Renamed from KSP_Parser.
KSP_Part: Removed some unused attributes.

file:a/KSP_Parser.py (deleted)
--- a/KSP_Parser.py
+++ /dev/null
@@ -1,87 +1,1 @@
-#!/usr/bin/python3

-

-#===============================================================================

-# Module-aware parser for KSP part and craft files.

-#===============================================================================

-

-from Modular import Component, MultiValueComponent

-from KSP_Part import *

-import KSP_Components

-from _tools import warn

-from collections import OrderedDict

-

-def main():

-	import argparse, os.path

-	

-	parser = argparse.ArgumentParser(description='Parse a KSP part file.')

-	parser.add_argument('files', metavar='FILE', type=str, nargs='+', help='The file or files to be parsed.')

-	

-	args = parser.parse_args()

-	

-	files = args.files

-	

-	globfiles = []

-	remove_indexes = []

-	for filename in files:

-		if filename.count('*') > 0:

-				from glob import glob

-				globfiles += glob(filename)

-				remove_indexes.append(filename)

-	for idx in remove_indexes:

-		files.remove(idx)

-	files += globfiles

-	

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

-	KSPDir = os.sep.join((partdir, '..', '..'))

-	

-	global resources

-	resources = Resource.createFromFile(os.sep.join((KSPDir, 'Resources', 'ResourcesGeneric.cfg')))

-	

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

-	parts = []

-	for filename in files:

-		_, ext = os.path.splitext(filename)

-		

-		if ext.lower() != '.cfg':

-			warn("Skipping file '{0}': Not a cfg file.".format(filename))

-			continue

-		

-		part = Part.createFromFile(filename)

-		for mvc in MultiValueComponent.__subclasses__():

-			if mvc.__name__ in part._components:

-				if mvc.__name__ not in csv_columns:

-					csv_columns[mvc.__name__] = set()

-				for key in getattr(part, "get{0}Node".format(mvc.__name__))().getValue().keys():

-					csv_columns[mvc.__name__].add(key)

-		#print(part)

-		parts.append(part)

-	

-	csv_columns.move_to_end('Title', last=False)

-	header1 = ["{0} {1}".format(o, k) for o in csv_columns for k in csv_columns[o]]

-	

-	print(','.join(header1))

-	

-	for part in parts:

-		row = []

-		for classname in csv_columns:

-			if classname in part._components:

-				node = getattr(part, "get{0}Node".format(classname))()

-			else:

-				node = None

-			classfields = []

-			for key in csv_columns[classname]:

-				if isinstance(node, MultiValueComponent):

-					if key in node.getValue():

-						classfields += [str(node.getValue()[key])]

-					else:

-						classfields += ['']

-				elif node is None:

-					classfields += ['']

-				else:

-					classfields += [str(node.getValue())]

-			row += classfields

-		print(','.join(row))

-

-if __name__ == "__main__":

-	main()

 

--- a/KSP_Part.py
+++ b/KSP_Part.py
@@ -17,7 +17,6 @@
 		self._type = blocktype

 		self._depth = depth

 		self._properties = {}

-		self._subparts = []

 		self._name = ''

 		self.filter = Component.filter

 		lastkey = ''


file:b/KSP_PartParser.py (new)
--- /dev/null
+++ b/KSP_PartParser.py
@@ -1,1 +1,87 @@
+#!/usr/bin/python3

+

+#===============================================================================

+# Module-aware parser for KSP part and craft files.

+#===============================================================================

+

+from Modular import Component, MultiValueComponent

+from KSP_Part import *

+import KSP_Components

+from _tools import warn

+from collections import OrderedDict

+

+def main():

+	import argparse, os.path

+	

+	parser = argparse.ArgumentParser(description='Parse a KSP part file.')

+	parser.add_argument('files', metavar='FILE', type=str, nargs='+', help='The file or files to be parsed.')

+	

+	args = parser.parse_args()

+	

+	files = args.files

+	

+	globfiles = []

+	remove_indexes = []

+	for filename in files:

+		if filename.count('*') > 0:

+				from glob import glob

+				globfiles += glob(filename)

+				remove_indexes.append(filename)

+	for idx in remove_indexes:

+		files.remove(idx)

+	files += globfiles

+	

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

+	KSPDir = os.sep.join((partdir, '..', '..'))

+	

+	global resources

+	resources = Resource.createFromFile(os.sep.join((KSPDir, 'Resources', 'ResourcesGeneric.cfg')))

+	

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

+	parts = []

+	for filename in files:

+		_, ext = os.path.splitext(filename)

+		

+		if ext.lower() != '.cfg':

+			warn("Skipping file '{0}': Not a cfg file.".format(filename))

+			continue

+		

+		part = Part.createFromFile(filename)

+		for mvc in MultiValueComponent.__subclasses__():

+			if mvc.__name__ in part._components:

+				if mvc.__name__ not in csv_columns:

+					csv_columns[mvc.__name__] = set()

+				for key in getattr(part, "get{0}Node".format(mvc.__name__))().getValue().keys():

+					csv_columns[mvc.__name__].add(key)

+		#print(part)

+		parts.append(part)

+	

+	csv_columns.move_to_end('Title', last=False)

+	header1 = ["{0} {1}".format(o, k) for o in csv_columns for k in csv_columns[o]]

+	

+	print(','.join(header1))

+	

+	for part in parts:

+		row = []

+		for classname in csv_columns:

+			if classname in part._components:

+				node = getattr(part, "get{0}Node".format(classname))()

+			else:

+				node = None

+			classfields = []

+			for key in csv_columns[classname]:

+				if isinstance(node, MultiValueComponent):

+					if key in node.getValue():

+						classfields += [str(node.getValue()[key])]

+					else:

+						classfields += ['']

+				elif node is None:

+					classfields += ['']

+				else:

+					classfields += [str(node.getValue())]

+			row += classfields

+		print(','.join(row))

+

+if __name__ == "__main__":

+	main()