Skip to content

Commit fcb9b10

Browse files
Upated creation of JSON file
- Switched from string concatenation to an object structure - Cleaned up code
1 parent 3ef648b commit fcb9b10

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

PropC_library_finder.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_files_in_directory( self, path ):
4343

4444
def assemble_information( self ):
4545
global library_path
46-
output = "[\n"
46+
output = {}
4747

4848
#get directories
4949
directories = self.get_subdirectories( library_path )
@@ -59,27 +59,18 @@ def assemble_information( self ):
5959
if ( "." not in sub_directory ):
6060
sub_directory_name = re.sub( "lib", "", sub_directory )
6161
sub_directory_path = directory_path + sub_directory
62-
63-
output += '\t{\n\t\t'
64-
output += '"name": "' + sub_directory_name + '",\n\t\t'
65-
output += '"libdir": "' + sub_directory_path + '",\n\t\t'
66-
output += '"include": [\n\t\t\t' + '"' + sub_directory_name + '"'
67-
output += '\n\t\t],\n\t\t'
68-
output += '"memorymodel": {\n\t\t\t"cmm": "' + sub_directory_path + '/cmm/"' + '\n\t\t}\n\t},\n'
62+
63+
output[ sub_directory_name ] = { "name" : sub_directory_name, "libdir" : sub_directory_path, "include" : sub_directory_name, "memorymode" : sub_directory_path + '/cmm/' }
6964
except:
7065
pass
71-
72-
output = output[:len(output) - 2]
73-
output += '\n]'
7466

7567
return output
7668

7769
def create_json_file( self, data, file_name ):
7870
file = open( file_name, 'w' )
79-
file.write( data )
71+
json.dump( data, file )
8072
file.close()
81-
82-
#json.dump( unicode( data ), file_name )
73+
8374
print json.load(open(os.getcwd() + "/lib-descriptor.json"))
8475

8576
def askdirectory(self, **options):

0 commit comments

Comments
 (0)