def testExplicitAssemblyLoad(self): """Test explicit assembly loading using standard CLR tools.""" from System.Reflection import Assembly import System, sys assembly = Assembly.LoadWithPartialName('System.Data') self.assertTrue(assembly != None) import System.Data self.assertTrue('System.Data' in sys.modules) assembly = Assembly.LoadWithPartialName('SpamSpamSpamSpamEggsAndSpam') self.assertTrue(assembly == None)
def test_explicit_assembly_load(): """Test explicit assembly loading using standard CLR tools.""" from System.Reflection import Assembly import System, sys assembly = Assembly.LoadWithPartialName('System.Data') assert assembly is not None import System.Data assert 'System.Data' in sys.modules assembly = Assembly.LoadWithPartialName('SpamSpamSpamSpamEggsAndSpam') assert assembly is None
major = MIN_NET2_VERSION / 100 minor = MIN_NET2_VERSION - major * 100 return "%d.%d" % (major, minor) class Net2XSException(Exception): """Exception class for net2 xs """ pass # The code below is required to determine if the already installed # Net2 version can be used, or that the packaged version is required. try: # Obtain paxton assembly reference asm = Assembly.LoadWithPartialName(PAXTON_ASSEMBLY) # Found: check the version if asm: ver = asm.GetName().Version if ver.Major * 100 + ver.Minor < MIN_NET2_VERSION: raise Net2XSException('Only Net2 V%s or higher is supported' % readable_min_version()) # Not found: enable the packaged paxton libs else: # Add path lib path to search path PAXTON_LIB_DIR = os.path.join(Net2Scripting.settings.LIB_DIR, 'paxton') if PAXTON_LIB_DIR not in sys.path: sys.path.append(PAXTON_LIB_DIR)
# furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import clr from System.Reflection import Assembly Assembly.LoadWithPartialName("Microsoft.HyperV.PowerShell.Objects") Assembly.LoadWithPartialName("Microsoft.HyperV.PowerShell.Cmdlets") clr.AddReference("System.Management") from System.Management import ManagementScope, ObjectQuery, ManagementObjectSearcher, ManagementObject, CimType, ManagementException, ManagementClass from System import Array, String, Guid from System.Management.Automation import PowerShell, PSObject # WARNING, clr_Array accepts iterable, e.g. if you will pass string - it will be array of its chars, not array of one # string. clr_Array[clr_String](["hello"]) equals to array with one "hello" string in it clr_Array = Array clr_String = String # make ide happy ManagementScope = ManagementScope ObjectQuery = ObjectQuery ManagementObjectSearcher = ManagementObjectSearcher ManagementObject = ManagementObject