本文整理汇总了Python中FileUtils.writeToFile方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtils.writeToFile方法的具体用法?Python FileUtils.writeToFile怎么用?Python FileUtils.writeToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtils
的用法示例。
在下文中一共展示了FileUtils.writeToFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restoreBackUp
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def restoreBackUp(_settingType="All", _isMakeBackUp=True):
files = []
isSuccessfully = True
if _settingType == "database" or _settingType == "All":
files.append("database.sqlite")
if _settingType == "Settings" or _settingType == "All":
files.append(uni.fileOfSettings)
for backupFile in files:
oldInfo = ""
if _isMakeBackUp:
oldInfo = fu.readFromFile(fu.joinPath(fu.pathOfSettingsDirectory, backupFile))
else:
try:
fu.removeFile(fu.joinPath(fu.pathOfSettingsDirectory, backupFile))
except: pass
try:
if fu.isFile(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile)):
fu.moveFileOrDir(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile),
fu.joinPath(fu.pathOfSettingsDirectory, backupFile))
else:
isSuccessfully = False
except: pass
if _isMakeBackUp:
fu.writeToFile(fu.joinPath(fu.pathOfSettingsDirectory, "BackUps", backupFile), oldInfo)
return isSuccessfully
示例2: saveStateOfSettings
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def saveStateOfSettings(_file):
from Core import MyConfigure
newFile = makeBackUp("Settings", "SettingFiles", "random")
info = MyConfigure.getConfiguredDesktopFileContent()
newInfo = []
for row in info.split("\n"):
if row[:4] == "Exec":
row = row + " -s SettingFiles" + fu.sep + newFile
newInfo.append(row)
info = ""
for row in newInfo:
info += row + "\n"
fu.writeToFile(_file, info)
示例3: createErrorPage
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def createErrorPage(self, _errorDetails):
_errorDetails = _errorDetails.replace("\"", """).replace("\'", "'")
language = "en_GB"
if "language" in uni.MySettings:
language = uni.MySettings["language"]
htmlString = (
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
'<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Hamsi Manager</title></head><body>' +
'<center>' +
'<form action="http://hamsiapps.com/ForMyProjects/ReportBug.php" method="post">' +
'<TABLE><TR><TD valign="top">%s'
'</TD><TD colspan=2><textarea ROWS="7" COLS="40" name="userNotes"></textarea></TD></TR></TABLE>' +
'<TABLE><TR><TD valign="top" colspan=2>%s</TD><TD align="right"><input type="search" name="nameAndSurname" value=""></input></TD></TR>' +
'<TR><TD valign="top" colspan=2>%s</TD><TD align="right"><input type="search" name="mail" value=""></input></TD></TR></TABLE>' +
'<TABLE><TR><TD align="right"><input name="send" type="submit" value=" %s "></TD></TR></TABLE>' +
'<INPUT TYPE="hidden" name="error" value="%s" />' +
'<INPUT TYPE="hidden" name="thankYouMessages" value="%s" />' +
'<INPUT TYPE="hidden" name="p" value="HamsiManager" />' +
'<INPUT TYPE="hidden" name="l" value="' + str(language) + '" />' +
'<INPUT TYPE="hidden" name="v" value="' + str(uni.intversion) + '" /></form>' +
'%s</center></body></html>'
) % (
str(translate("ReportBug",
"<b>Error description :</b> <br>(Be can null)<br><b>Note:</b>Please write what you did before you received the error here.")),
str(translate("ReportBug", "<b>Name and Surname :</b> (Be can null)")),
str(translate("ReportBug",
"<b>E-mail address :</b> (Be can null)<br><b>Note:</b>Will be kept strictly confidential. It will be used solely to report you back once the problem is solved..")),
str(translate("ReportBug", "Report Bug")),
_errorDetails,
str(translate("ReportBug",
"Thank you for sending us your error report. You have already contributed a lot to make the next release even better..<br>")),
_errorDetails)
if self.pathOfReportFile is None:
import random
self.pathOfReportFile = fu.joinPath(fu.getTempDir(), "HamsiManager-ErrorOutput-" + str(
random.randrange(0, 1000000)) + ".html")
fu.writeToFile(self.pathOfReportFile, htmlString)
示例4: reConfigure
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def reConfigure(self):
try:
oldPathOfExecutableHamsi = Settings.getUniversalSetting("HamsiManagerExecutableLinkPath", "/usr/bin/hamsi")
if fu.isFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")):
if fu.isWritableFileOrDir(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop")):
MyConfigure.reConfigureFile(fu.joinPath(fu.HamsiManagerDirectory, "HamsiManager.desktop"))
if self.isCreateDesktopShortcut is not None:
if self.isCreateDesktopShortcut.checkState() == Mt.Checked:
desktopPath = uni.getUserDesktopPath()
if uni.isWindows:
MyConfigure.createShortCutFile(fu.joinPath(desktopPath, "Hamsi Manager.lnk"))
else:
fileContent = MyConfigure.getConfiguredDesktopFileContent()
fu.writeToFile(fu.joinPath(desktopPath, "HamsiManager.desktop"), fileContent)
if uni.isRunningAsRoot():
executableLink = str(self.leExecutableLink.text())
if self.isCreateExecutableLink is not None:
if self.isCreateExecutableLink.checkState() == Mt.Checked:
if executableLink.strip() != "":
HamsiManagerFileName = Execute.findExecutableBaseName("HamsiManager")
if fu.isFile(executableLink):
fu.removeFileOrDir(executableLink)
fu.createSymLink(fu.joinPath(fu.HamsiManagerDirectory, HamsiManagerFileName),
executableLink)
Settings.setUniversalSetting("HamsiManagerExecutableLinkPath", executableLink)
if oldPathOfExecutableHamsi != executableLink:
if fu.isFile(oldPathOfExecutableHamsi):
answer = Dialogs.ask(translate("Reconfigure", "Other Hamsi Manager Was Detected"),
str(translate("Reconfigure",
"Other Hamsi Manager executable file was detected. Are you want to delete old executable file? You can delete this old executable file : \"%s\"")) % (
oldPathOfExecutableHamsi))
if answer != Dialogs.Yes:
fu.removeFile(oldPathOfExecutableHamsi)
if fu.isDir("/usr/share/applications/"):
fileContent = MyConfigure.getConfiguredDesktopFileContent()
fu.writeToFile("/usr/share/applications/HamsiManager.desktop", fileContent)
if uni.isRunningAsRoot() is False:
if fu.isDir(fu.joinPath(fu.userDirectoryPath, ".local", "applications")) is False:
fu.makeDirs(fu.joinPath(fu.userDirectoryPath, ".local", "applications"))
fileContent = MyConfigure.getConfiguredDesktopFileContent()
fu.writeToFile(fu.joinPath(fu.userDirectoryPath, ".local", "applications", "HamsiManager.desktop"),
fileContent)
MyConfigure.installKDE4Languages()
self.isInstallFinished = True
except:
ReportBug.ReportBug()
示例5: finish
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def finish(self):
try:
if fu.isFile(fu.joinPath(self.installationDirectory, "HamsiManager.desktop")):
MyConfigure.reConfigureFile(fu.joinPath(self.installationDirectory, "HamsiManager.desktop"),
self.installationDirectory)
if self.isCreateDesktopShortcut is not None:
if self.isCreateDesktopShortcut.checkState() == Mt.Checked:
desktopPath = uni.getUserDesktopPath()
if uni.isWindows:
MyConfigure.createShortCutFile(fu.joinPath(desktopPath, "Hamsi Manager.lnk"),
self.installationDirectory)
else:
fileContent = MyConfigure.getConfiguredDesktopFileContent(self.installationDirectory)
fu.writeToFile(fu.joinPath(desktopPath, "HamsiManager.desktop"), fileContent)
if self.isCreateExecutableLink is not None:
executableLink = str(self.leExecutableLink.text())
if self.isCreateExecutableLink.checkState() == Mt.Checked:
if executableLink.strip() != "":
executableLink = fu.checkNewDestination(executableLink)
if executableLink:
HamsiManagerFileName = Execute.findExecutableBaseName("HamsiManager")
fu.createSymLink(fu.joinPath(self.installationDirectory, HamsiManagerFileName),
executableLink)
Settings.setUniversalSetting("HamsiManagerExecutableLinkPath", executableLink)
if fu.isDir("/usr/share/applications/"):
fileContent = MyConfigure.getConfiguredDesktopFileContent(self.installationDirectory)
fu.writeToFile("/usr/share/applications/HamsiManager.desktop", fileContent)
if uni.isRunningAsRoot() is False:
if fu.isDir(fu.joinPath(fu.userDirectoryPath, ".local", "applications")) is False:
fu.makeDirs(fu.joinPath(fu.userDirectoryPath, ".local", "applications"))
fileContent = MyConfigure.getConfiguredDesktopFileContent(self.installationDirectory)
fu.writeToFile(fu.joinPath(fu.userDirectoryPath, ".local", "applications", "HamsiManager.desktop"),
fileContent)
self.isInstallFinished = True
self.close()
except:
from Core import ReportBug
ReportBug.ReportBug()
示例6: print
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
SOURCES = ""
TRANSLATIONS = ""
directoriesAndFiles = fu.readDirectoryWithSubDirectories(fu.HamsiManagerDirectory)
for fileName in directoriesAndFiles:
if (fu.isFile(fileName) and fileName.find(".py") > -1 and
fileName.find(".pyc") == -1 and fileName.find(".pyw") == -1):
SOURCES += fileName.replace(fu.HamsiManagerDirectory + fu.sep, "") + " \\\n "
for fileName in ["Languages" + fu.sep + "HamsiManager_tr_TR.ts",
"Languages" + fu.sep + "HamsiManager_untranslated.ts"]:
TRANSLATIONS += fileName + " \\\n "
proFileContent = proFileContent.replace("%SOURCES%", SOURCES)
proFileContent = proFileContent.replace("%TRANSLATIONS%", TRANSLATIONS)
fu.writeToFile(proFile, proFileContent)
args = ["pylupdate4"]
#args.append("-noobsolete") # Uncomment me if you want to remove old translations from .ts files.
args.append("-verbose")
args.append(proFile)
print (Execute.getCommandResult(args, fu.HamsiManagerDirectory))
proFileContent = proFileContent.replace("Languages" + fu.sep + "HamsiManager_untranslated.ts \\\n ", "")
fu.writeToFile(proFile, proFileContent)
args = ["lrelease"]
args.append("-compress")
args.append(proFile)
print (Execute.getCommandResult(args, fu.HamsiManagerDirectory))
示例7: clearRecords
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def clearRecords():
fu.writeToFile(fu.recordFilePath, str(translate("Records", "Hamsi Manager Record File - Time Clear : ")) + str(
time.strftime("%d.%m.%Y %H:%M:%S")) + "\n")
示例8: reConfigureFile
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
def reConfigureFile(_filePath, _installationDirectory=fu.HamsiManagerDirectory, _executeCommandOfHamsiManager=None):
fileContent = getConfiguredContent(fu.readFromFile(_filePath), _executeCommandOfHamsiManager)
fileContent = fileContent.replace(fu.HamsiManagerDirectory, _installationDirectory)
fu.writeToFile(_filePath, fileContent)
示例9: str
# 需要导入模块: import FileUtils [as 别名]
# 或者: from FileUtils import writeToFile [as 别名]
import FileUtils as fu
includes = []
excludes = ["_gtkagg", "_tkagg", "bsddb", "curses", "email",
"pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs",
"tcl", "Tkconstants", "Tkinter", "PySide"]
path = sys.path + [HamsiManagerDirectory]
include_files = [(os.path.join(HamsiManagerDirectory, "Amarok"), "Amarok"),
(os.path.join(HamsiManagerDirectory, "Languages"), "Languages"),
(os.path.join(HamsiManagerDirectory, "MyPlugins"), "MyPlugins"),
(os.path.join(HamsiManagerDirectory, "SearchEngines"), "SearchEngines"),
(os.path.join(HamsiManagerDirectory, "Taggers"), "Taggers"),
(os.path.join(HamsiManagerDirectory, "Themes"), "Themes")]
fu.writeToFile(fu.joinPath(fu.getTempDir(), "HamsiManagerHasBeenBuilt"),
str(sys.argv) + "\nPlease, don't remove this file.")
include_files.append((os.path.join(fu.getTempDir(), "HamsiManagerHasBeenBuilt"), "HamsiManagerHasBeenBuilt"))
data_files = []
if os.name == "posix":
from Core import MyConfigure
installationDirectory = fu.joinPath("/", "usr", "lib", "HamsiManager-" + uni.version)
fileContent = MyConfigure.getConfiguredDesktopFileContent(installationDirectory, "/usr/bin/hamsi")
fu.writeToFile(fu.joinPath(fu.getTempDir(), "HamsiManager.desktop"), fileContent)
data_files.append(
(fu.joinPath("/", "usr", "share", "applications"), [fu.joinPath(fu.getTempDir(), "HamsiManager.desktop")]))
if uni.isAvailableKDE4():
for langCode in uni.getInstalledLanguagesCodes():