/
required.py
162 lines (130 loc) · 5.34 KB
/
required.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# -*- coding: utf-8 -*-
"""
.. created on Sat Mar 17 20:35:40 2018
.. author: PE LLC peswin@mindspring.com
.. copyright: 2018, Howard Dunn. Apache 2.0 v2 licensed.
"""
from version import __version__
import os
from os import path as op
from os.path import exists as opex
from os.path import join as opj
from os.path import normpath as opn
from os.path import dirname as opd
from os.path import abspath as opab
from globalstate import gsBuild
if __name__ != '__main__':
from partialerror import FatalError, partialError
from makedefault import DefaultReqList
from buildlogs import dynfile
log = dynfile(__name__)
log.debug('\n---------------- ' + str(__name__) + \
' loaded ---------------')
gsBuild.REQUIRED = []
gsBuild.HAVELIB = False
gsBuild.HAVELIBDLL = False
gsBuild.requiredPath = 'requirements.txt'
gsBuild.IRONPYTHON = 'License.StdLib.txt'
def FindIronPython():
'''
Walk directories to find IronPython Install
:return: IronPython install path [str] - or - if not main sets gsBuild.IPATH
:raise: NotImplementedError
'''
clr = None
try:
import clr
except Exception as ex:
pass
SEARCHUSER = opn(os.path.expanduser('~'))
SEARCHCWD = opd(os.getcwd())
if 'Tests' in os.getcwd():
SEARCHCWD = opd(SEARCHCWD)
SEARCHMODSRC = opn(opd(opd(os.__file__)))
SEARCHROOT = os.path.splitdrive(SEARCHCWD)[0]
searchList = [SEARCHCWD, SEARCHUSER, SEARCHMODSRC, SEARCHROOT]
for direct in searchList:
for root, dirs, files in os.walk(direct, topdown=False):
for name in files:
if gsBuild.IRONPYTHON in name:
with open(opn(opab(opj(os.getcwd(),
'defaults\\ipath.txt'))),
'w') as tw:
tw.write(opd(opn(opj(root, name))))
return opd(opn(opj(root, name)))
if __name__ == '__main__':
raise NotImplementedError('Failed to Find/*Access' + \
' loadable IronPython Distribution')
if clr:
#print str(clr.References)
with open(opn(opab(opj(os.getcwd(),
'defaults\\ipath.txt'))), 'w') as tw:
tw.write('clr')
print 'Err in clr req'
return 'clr'
if not clr:# or (clr and clr.References and not any('Iron' in clref for clref in str(clr.References).split(','))):
log.warn(('\nFailed to find loadable IronPython Distribution:\n Used "{}"' + \
' name to search for directory.\n\n' +
' Searched ordered from base:\n {}\n {}\n {}\n {}\n') \
.format(gsBuild.IRONPYTHON, *searchList))
log.info('\nCheck Access and/or install IronPython to loadable path.')
raise FatalError('NotImplementedError', 'Failed to Find/*Access' + \
' loadable IronPython Distribution')
return
def checkRequiredIP():
clr = None
if gsBuild.IPATH:
return
try:
import clr
except Exception as ex:
pass
ironPythonPath = None
userReqBaseLst = None
userReqLst = None
gsBuild.HAVELIB
gsBuild.HAVELIBDLL
ironPythonPath = FindIronPython()
if clr:
gsBuild.HAVELIB = False
if opex(opj(os.getcwd(),'StdLib.dll')):
gsBuild.HAVELIBDLL = True
if not clr or (clr and ironPythonPath and ironPythonPath != 'clr'):
#ironPythonPath = FindIronPython()
if opex(ironPythonPath):
gsBuild.IPATH = ironPythonPath
userReqBaseLst = os.listdir(ironPythonPath)
userReqLst = [opn(opj(ironPythonPath, urf))
for urf in os.listdir(ironPythonPath)]
if opex(opj(ironPythonPath, 'Lib')):
log.FILE('Exists: {}'.format(opj(ironPythonPath, 'Lib')))
gsBuild.HAVELIB = True
# TODO check for downloaded StdLib
if op.isfile(opn(opj(ironPythonPath, 'StdLib.dll'))):
gsBuild.HAVELIBDLL = True
if not all(rf in userReqBaseLst for rf in DefaultReqList):
try:
raise NotImplementedError
except NotImplementedError as ex:
msg = 'Failed to find all required IronPython Distribution files'
partialError(ex, msg)
log.FILE('\n Exists required path {}' \
.format(opj(os.getcwd(), gsBuild.requiredPath)))
WD = os.getcwd()
if 'Tests' in WD:
WD = opd(WD)
with open(opj(os.getcwd(), gsBuild.requiredPath), 'w') as tw:
for f in userReqLst:
relp = opn(op.relpath(f))
# skip dirs
if op.isfile(relp):
tw.write(opn(os.path.relpath(f)) + '\n')
log.FILE('Exists {}'.format(gsBuild.requiredPath))
elif clr and (not ironPythonPath or ironPythonPath == 'clr'):
gsBuild.IPATH = 'clr'
return
if __name__ == '__main__':
print('Please wait (~30 sec) to find IronPython...')
gsBuild.IRONPYTHON = 'License.StdLib.txt'
print('IronPyhton found by looking for: "{}"\nInstalled in:\n\t{}' \
.format(gsBuild.IRONPYTHON, FindIronPython()))