示例#1
0
文件: __init__.py 项目: yncat/falcon
 def unpickle(self, name):
     """ファイルから状態を読み込む。よみこめなかったらFalse。"""
     temp = win32api.GetEnvironmentVariable("TEMP")
     self.log.debug("Loading fileOp state from %s" % name)
     fi = name + "i"
     fo = name + "o"
     try:
         f = open(temp + "\\" + fi, "rb")
     except IOError as er:
         self.log.error("Cannot read %s (%s)" % (fi, str(er)))
         return False
     # end except
     try:
         self.instructions = pickle.load(f)
     except (pickle.PickleError, EOFError) as err:
         self.log.error("Cannot extract %s(%s)" % (fi, str(err)))
         return False
     # end except
     f.close()
     try:
         f = open(temp + "\\" + fo, "rb")
     except IOError as er:
         self.log.error("Cannot read %s (%s)" % (fo, str(er)))
         return False
     # end except
     try:
         self.output = pickle.load(f)
     except (pickle.PickleError, EOFError) as err:
         self.log.error("Cannot extract %s(%s)" % (fo, str(err)))
         return False
     # end except
     f.close()
     os.remove(temp + "\\" + fi)
     os.remove(temp + "\\" + fo)
     return True
示例#2
0
def which_file(fname):
    """prints paths for fname where fname can be found,
	in case of .dll loads it"""
    files = []
    path = win32api.GetEnvironmentVariable('PATH')
    # try paths as described in MSDN
    dirs = [
        os.getcwd(),
        win32api.GetSystemDirectory(),
        win32api.GetWindowsDirectory()
    ] + path.split(';')
    dirs_norm = []
    dirs_l = []
    for d in dirs:
        dn = d.lower()
        if dn not in dirs_l:
            dirs_l.append(dn)
            dirs_norm.append(d)
    for d in dirs_norm:
        fname2 = os.path.join(d, fname)
        if os.path.exists(fname2):
            if fname2 not in files:
                files.append(fname2)
    if files:
        print('\n'.join([get_file_info(f) for f in files]))
    h = 0
    if fname.lower().endswith('.dll'):
        print('\ttrying to load "%s" ...' % (fname))
        try:
            h = win32api.LoadLibrary(fname)
            if h:
                dll_name = win32api.GetModuleFileName(h)
                print('\t%s loaded' % (dll_name))
        except:
            print('\tCannot load "%s" !!!' % (fname))
示例#3
0
    def install(self):
        if not os.path.exists(self.install_dir):
            log.info('creating {}'.format(self.install_dir))
            os.makedirs(self.install_dir)

        self.copy_file(os.path.join('../', 'tests', self.module_name),
                       os.path.join(self.install_dir, self.module_name))

        # When compiled with Microsoft Visual C++, the JSBSim Python module is
        # linked with the dynamically linked library msvcp140.dll which is not a
        # standard library on Windows. So this code allows msvcp140.dll to be
        # shipped with the Python module.
        if compiler.compiler_type == 'msvc':
            import win32api

            path = win32api.GetEnvironmentVariable('PATH')
            # Use a set below to remove duplication.
            dirs = set([win32api.GetSystemDirectory(),
                        win32api.GetWindowsDirectory()] + path.split(';'))

            for d in dirs:
                libpath = os.path.join(d, 'msvcp140.dll')
                if os.path.exists(libpath):
                    self.copy_file(libpath, os.path.join(self.install_dir,
                                                         'msvcp140.dll'))
                    break
示例#4
0
 def pickle(self, name=""):
     """ファイルオペレーションの現在の状態を、テンポラリフォルダに保存する。保存したファイル名(完全なファイル名ではない)を帰す。これをそのまま unpickle に渡す。固められなかったらFalse。name に指定すると、強制的にその名前で書く。"""
     temp = win32api.GetEnvironmentVariable("TEMP")
     if name != "":
         fi = name + "i"
         fo = name + "o"
     else:
         while (True):
             r = random.randint(0, 9999)
             fi = "falcon%04di" % r
             fo = "falcon%04do" % r
             if os.path.isfile(fi) or os.path.isfile(fo): continue
             break
         #end 保存できるファイル名を探す処理
     #end 強制指定かそうでないか
     self.log.debug(
         "Saving file operation status: directory=%s, filename=%s, %s" %
         (temp, fi, fo))
     try:
         f = open(temp + "\\" + fi, "wb")
     except IOError:
         self.log.error("Failed to write to %s" % fi)
         return False
     #end except
     pickle.dump(self.instructions, f)
     f.close()
     try:
         f = open(temp + "\\" + fo, "wb")
     except IOError as er:
         self.debug.error("Failed to write to %s" % fo)
         return False
     #end except
     pickle.dump(self.output, f)
     f.close()
     return "falcon%04d" % (r) if name == "" else name
def get_working_dir(applicationname):
    if sys.platform == 'win32':
        import win32api
        username = win32api.GetUserName()
        working_dir = os.path.join(
            win32api.GetEnvironmentVariable('USERPROFILE'),
            'Application data/%s' % applicationname)
    if sys.platform[:5] == 'linux':
        working_dir = os.path.join(os.path.expanduser("~"),
                                   '.%s/' % applicationname)
    if sys.platform == 'darwin':
        working_dir = os.path.join(os.path.expanduser("~"),
                                   '.%s/' % applicationname)
    if not (os.path.isdir(working_dir)):
        os.mkdir(working_dir)
    return working_dir
示例#6
0
def WindowsCompletePath():
    path = win32api.GetEnvironmentVariable('PATH')
    dirs = [
        os.getcwd(),
        win32api.GetSystemDirectory(),
        win32api.GetWindowsDirectory()
    ] + path.split(';')

    dirs_norm = []
    dirs_l = []
    for aDir in dirs:
        aDirLower = aDir.lower()
        if aDirLower not in dirs_l:
            dirs_l.append(aDirLower)
            dirs_norm.append(aDir)

    return dirs_norm
示例#7
0
def WindowsCompletePath():
    """Try paths as described in MSDN"""
    path = win32api.GetEnvironmentVariable('PATH')
    dirs = [
        os.getcwd(),
        win32api.GetSystemDirectory(),
        win32api.GetWindowsDirectory()
    ] + path.split(';')

    dirs_norm = []
    dirs_l = []
    for a_dir in dirs:
        a_dir_lower = a_dir.lower()
        if a_dir_lower not in dirs_l:
            dirs_l.append(a_dir_lower)
            dirs_norm.append(a_dir)

    return dirs_norm
示例#8
0
    def __init__(self, grph):
        self.grph = grph
        self.path = win32api.GetEnvironmentVariable('PATH')

        # try paths as described in MSDN
        self.dirs = [
            os.getcwd(),
            win32api.GetSystemDirectory(),
            win32api.GetWindowsDirectory()
        ] + self.path.split(';')

        self.dirs_norm = []
        dirs_l = []
        for aDir in self.dirs:
            aDirLower = aDir.lower()
            if aDirLower not in dirs_l:
                dirs_l.append(aDirLower)
                self.dirs_norm.append(aDir)
def look_for(fname):
    """prints paths for fname where fname can be found"""
    files = []
    path = win32api.GetEnvironmentVariable('PATH')
    
    # try paths as described in MSDN
    dirs = [os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory()] + path.split(';')
    for d in dirs:
        fname2 = os.path.join(d, fname)
        if os.path.exists(fname2):
            if not fname2 in files:
                files.append(fname2)
    if len(files) > 1:
        print '===== SHARED LIBRARY WARNING: There is more than one: ' + fname + ' on the search path!! ====='                        
    if files:
        #print '\n'.join([f for f in files])        
        #Return the first found path
        return files[0]
    else:
        return None       
                 
示例#10
0
import os
import logging
import lib_util

# This returns the full path name of a shared library file name.
# This works in similar ways on Windows on Linux.
# The difference is in the PATH.

# This is done only once because it should not change in a process lifetime.

if lib_util.isPlatformWindows:
    import win32api
    library_search_path = []
    path = win32api.GetEnvironmentVariable('PATH')

    # try paths as described in MSDN
    dirs = [
        os.getcwd(),
        win32api.GetSystemDirectory(),
        win32api.GetWindowsDirectory()
    ] + path.split(';')

    dirs_lower = set()
    for one_dir in dirs:
        a_dir_lower = one_dir.lower()
        if a_dir_lower not in dirs_lower:
            dirs_lower.add(a_dir_lower)
            library_search_path.append(one_dir)

if lib_util.isPlatformLinux:
    library_search_path = os.environ["PATH"].split(':')
示例#11
0
import win32api as api
import win32con as con
for disk in "CDEF":
    F = api.GetDiskFreeSpace(disk + ":")
    rest = F[0] * F[1] * F[2] / 1e9
    total = F[0] * F[1] * F[3] / 1e9
    print("Rest:", rest, "G", "Total:", total, "G")
print(api.GetComputerName())
print(api.GetConsoleTitle())
print(api.GetCommandLine())
print(api.GetCursorPos())
print(api.GetDomainName())
print(api.GetEnvironmentVariable('path'))
print(api.GetFileAttributes('.'))
print(api.GetFileVersionInfo('C:\\windows\\system32\\cmd.exe', "\\"))
print(api.GetFullPathName('.'))
print(api.GetLocalTime())
print(api.GetLogicalDriveStrings().replace('\x00', ' '))
print(api.GetLogicalDrives())
print(api.GetLongPathName('C:'))
print(api.GetModuleFileName(0))
print(api.GetNativeSystemInfo())
print(hex(api.GetSysColor(con.COLOR_WINDOW)))
print(api.GetSystemDirectory())
print(api.GetSystemInfo())
print(api.GetSystemMetrics(con.SM_CXSCREEN))
print(api.GetSystemTime())
print(api.GetTickCount())
# print(api.GetTimeZoneInformation())
print(api.GetUserDefaultLangID())
print(api.GetUserName())
    # Acquire options for CheckResources
    if optionlist.count(str(sys.argv[2]).upper()) == 1:
        option = "TEST"
        extent = str(sys.argv[2]).upper()
    # Acquire options for CreatePartitionFeatureClass    
    else:
        option = "TILE"
        output = sys.argv[2]
        extent = str(sys.argv[3]).upper()
        
    # Determine scratch workspace to use for file messages
    scratchWS = GP.scratchWorkspace
    if scratchWS:
        desc = GP.Describe(scratchWS)
        if desc.WorkspaceType <> "FileSystem":
            scratchWS = win32api.GetEnvironmentVariable("TEMP")         
    else:
        scratchWS = win32api.GetEnvironmentVariable("TEMP")

    messagetarget = scratchWS + "/xxxResources.txt"

    # Execute for CheckResources
    if option == "TEST":
        os.system(location + "/testgpram.exe" + " " + inputs + " " + option + " " + messagetarget + " " + extent)
    # Execute for CreatePartitionFeatureClass
    else:
        os.system(location + "/testgpram.exe" + " " + inputs + " " + option + " " + "\"" + output + "\"" + " " + extent + " " + messagetarget)

    # Return GP Messages
    messagefile = open(messagetarget, 'r')
    messagestring = messagefile.read()