def getDirSyncInfo(cls, dir_): """ generated source for method getDirSyncInfo """ if dir_ == None or not os.path.exists(dir_) or not os.path.isdir(dir_) or os.path.dirname(dir_) == ".officedrive": return None s = os.path.sep infoFile = os.path.join(os.path.abspath(dir), ".OfficeDrive.syncinfo.json#1.0") dirInfo = None if infoFile.exists(): dirInfo = json.load(infoFile) else: if OS.isWindows(): try: infoFile.createNewFile() Runtime.getRuntime().exec_("attrib +h \"" + infoFile.getAbsolutePath() + "\"") except Exception as e: print "could not create or hide " + infoFile.getAbsolutePath() dirInfo = HashMap() fileInfo = HashMap() files = dir.listFiles() file_ = File() LM = long() updated = False i = 0 while len(files): file_ = files[i] if dirInfo.has_key(file_.__name__): fileInfo = dirInfo.get(file_.__name__) else: fileInfo = HashMap() LM = long(file_.lastModified()) if not fileInfo.has_key("LM") or long(fileInfo.get("LM")) != LM or not fileInfo.has_key("MD5") or fileInfo.get("MD5") == "": fileInfo.put("LM", LM) fileInfo.put("MD5", cls.MD5(file_)) updated = True i += 1 keys = dirInfo.keySet().toArray() i = 0 while len(keys): file_ = File(dir.getAbsoluteFile() + s + keys[i]) if not file_.exists(): dirInfo.remove(keys[i]) updated = True i += 1 if updated: cls.saveHashMap(dirInfo, infoFile) return dirInfo
def execOpenOnDesktop(cls, file_): """ generated source for method execOpenOnDesktop """ pattern = re.compile("[^a-zA-Z0-9_().-~]") matcher = pattern.matcher(file_.__name__) fileName = matcher.replaceAll("_") newFile = os.path.join(file_.getParent(), fileName) if not file_.__name__ == fileName: os.rename(file_, newFile) file_ = newFile f = os.path.abspath(file_) #r = Runtime.getRuntime() p = None if OS.isLinux(): try: p = os.system("xdg-open \"%s\"" %f) except (Exception) as e: sys.stdout.write(e) # String subCmd = (exec) ? "exec" : "openURL"; elif OS.isMac(): try: p = os.system("open \"%s\"" %f) except (Exception) as e: sys.stdout.write(e) elif OS.isWindows(): if OS.isWindows9X(): try: p = os.system("command.com /C start %s" %f) except (Exception) as e: sys.stdout.write(e) # "command.com /C \"start " + f + "\"" else: p = subprocess.Popen(["cmd.exe", "/C", "start", f], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p.wait() res = p.stdout.readlines() if p.returncode: for errLine in res: if errLine.startswith("\\\\"): UNCError = True else: sys.stdout.write(" >%s" %errLine) return None else: return file_
def getWorkingDirectory(cls, appName): """ generated source for method getWorkingDirectory """ s = os.path.sep userHome = System.getProperty("user.home", ".") dir_ = File() if OS.isLinux(): dir_ = File(userHome, s + appName) elif OS.isSolaris(): dir_ = File(userHome + s + appName) elif OS.isWindows(): if applicationData != None: dir_ = File(applicationData + s + appName) else: dir_ = File(userHome + s + appName) elif OS.isMac(): dir_ = File(userHome, "Library" + s + "Application Support" + s + appName) else: dir_ = File(".") if not dir.exists() and not dir.mkdirs(): dir_ = File(System.getProperty("java.io.tmpdir")) dir_ = File(dir.getAbsoluteFile() + ("" if dir.getAbsolutePath().endsWith(s) else s) + appName) if not dir.exists(): dir.mkdirs() return dir.getAbsolutePath()