forked from parallaxinc/BlocklyPropClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PropC_library_finder.py
98 lines (69 loc) · 2.78 KB
/
PropC_library_finder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
__author__ = 'Vale'
import platform
import os
import json
import subprocess
import re
import tkMessageBox
import tkFileDialog
from tkCommonDialog import Dialog
class propc_library_finder:
library_path = ""
def __init__( self, *args, **kwargs ):
self.find_libraries()
output = self.assemble_information()
self.create_json_file( output, "lib-descriptor.json" )
def get_directory( self ):
global library_path
return library_path
def find_libraries( self ):
global library_path
file_path = self.askdirectory()
library_path = file_path
def get_subdirectories( self, path ):
return os.listdir( path )
def get_files_in_directory( self, path ):
files = []
for file in os.listdir( path ):
if isfile( file ):
files[ file ] = file
return files
def assemble_information( self ):
global library_path
output = {}
#get directories
directories = self.get_subdirectories( library_path )
for directory in directories:
directory_path = library_path + "/" + directory + "/"
#get subdirectories of that directory
try:
sub_directories = self.get_subdirectories( directory_path )
for sub_directory in sub_directories:
if ( "." not in sub_directory ):
sub_directory_name = re.sub( "lib", "", sub_directory )
sub_directory_path = directory_path + sub_directory
output[ sub_directory_name ] = { "name" : sub_directory_name, "libdir" : sub_directory_path, "include" : sub_directory_name, "memorymode" : sub_directory_path + '/cmm/' }
except:
pass
return output
def create_json_file( self, data, file_name ):
file = open( file_name, 'w' )
json.dump( data, file )
file.close()
print json.load(open(os.getcwd() + "/lib-descriptor.json"))
def askdirectory(self, **options):
"Ask for a directory name"
return apply(self.Chooser, (), options).show()
class Chooser(Dialog):
command = "tk_chooseDirectory"
def _fixresult(self, widget, result):
if result:
# keep directory until next time
self.options["initialdir"] = result
self.directory = result # compatibility
return result
#
# convenience stuff
if __name__ == '__main__':
tkMessageBox.showinfo( "ERROR", "This program cannot be run as a standalone application" )
#library_finder_test = propc_library_finder()