-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_loader.py
More file actions
127 lines (112 loc) · 4.03 KB
/
dynamic_loader.py
File metadata and controls
127 lines (112 loc) · 4.03 KB
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
######################################################
# Purpose: To load modules dynamically so that used #
# modules work properly and consistantly #
# across different Python installations #
######################################################
#----------------------------------------------------#
# Purpose: To load the XML parser module dynamically #
# Parameters: N/A #
# Return: Boolean - if it was successful #
# Additional Notes: This allows classes to reference #
# the etree object for XML parsing #
# via a call to #
# <dynamic_loader>.etree #
#----------------------------------------------------#
def load_XML_parser():
# Boolean flag to represent if the import worked (default to False as
# want to assume NOT imported until know otherwise)
success = False
# Make the import global to the file and by extension accessible to
# other modules
global etree
try:
# Load the etree from/as the lxml package or module
from lxml import etree
# DEBUGGING: A print statement to allow the "user" to know
# which version was imported
#print("running with lxml.etree")
# Since we've successfully imported the etree from/as the lxml
# package or module reset the Boolean flag to True
success = True
except ImportError:
try:
# Load the etree from/as the xml.etree package or
# module (Python 2.5)
import xml.etree.cElementTree as etree
# DEBUGGING: A print statement to allow the "user" to
# know which version was imported
#print("running with cElementTree on Python 2.5+")
# Since we've successfully imported the etree from/as
# the xml.etree package or module reset the Boolean flag
# to True
success = True
except ImportError:
try:
# Load the etree from/as the xml.etree package
# or module (Python 2.5)
import xml.etree.ElementTree as etree
# DEBUGGING: A print statement to allow the
# "user" to know which version was
# imported
#print("running with ElementTree on Python 2.5+")
# Since we've successfully imported the etree
# from/as the xml.etree package or module reset
# the Boolean flag to True
success = True
except ImportError:
try:
# Load the etree from/as the
# cElementTree (normal cElementTree
# install)
import cElementTree as etree
# DEBUGGING: A print statement to allow
# the "user" to know which
# version was imported
#print("running with cElementTree")
# Since we've successfully imported the
# etree from/as the cElementTree package
# or module reset the Boolean flag to
# True
success = True
except ImportError:
try:
# Load the etree from/as the
# ElementTree (normal
# ElementTree install)
import elementtree.ElementTree as etree
# DEBUGGING: A print statement
# to allw the "user"
# to know which
# version was
# imported
#print("running with ElementTree")
# Since we've successfully
# imported the etree from the
# ElementTree package or module
# reset the Boolean flag to True
success = True
except ImportError:
# DEBUGGING: A print statement
# to allow the "user"
# to know that we
# couldn't seem to
# import any version
# successfully
print("Failed to import ElementTree from any known place")
# Return the Boolean flag
return success
def load_abc():
global abc
import abc
def load_subprocess():
global subprocess
import subprocess
def load_json():
global json
import json
def load_Metadata_Record():
global Metadata_Record
from Metadata_Record import Metadata_Record
def load_data_structs():
global structs
import data_structs as structs