本文整理匯總了Python中rapuma.core.tools.Tools.renameFile方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.renameFile方法的具體用法?Python Tools.renameFile怎麽用?Python Tools.renameFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.renameFile方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Macro
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import renameFile [as 別名]
#.........這裏部分代碼省略.........
macPackId = self.getMacPackIdFromSource(source)
confXml = os.path.join(self.local.projMacroFolder, macPackId, macPackId + '.xml')
oldMacPackId = self.projectConfig['CompTypes'][self.cType.capitalize()]['macroPackage']
oldMacDir = os.path.join(self.local.projMacroFolder, oldMacPackId)
newMacDir = os.path.join(self.local.projMacroFolder, macPackId)
# Install the new macPack (but use the old settings)
if self.installMacPackOnly(source) :
# The current macro system must have a "master" style file.
# This is a version of the ParaText style file. Because
# an update might include an update to the style file,
# we need to copy that from the macro folder to the Style
# folder. We will do that now. The name of the file should
# be the macPackId + ".sty", in theory.
srcStyleFile = os.path.join(self.local.projMacroFolder, macPackId, macPackId + '.sty')
oldStyleFile = os.path.join(self.local.projStyleFolder, oldMacPackId + '.sty')
newStyleFile = os.path.join(self.local.projStyleFolder, macPackId + '.sty')
# Unlock the old one so it can be deleted.
self.tools.makeExecutable(oldStyleFile)
self.tools.removeFile(oldStyleFile)
# Now copy in the new one.
shutil.copy(srcStyleFile, newStyleFile)
# The style file should never be edited by the user, relock it
self.tools.makeReadOnly(newStyleFile)
# Update exsisting extention file names. We never want to loose
# any settings that the user may have added to the extention
# files so we will rename the existing files to have the
# new ID otherwise the system will not find them at render time.
oldStyExtFile = os.path.join(self.local.projStyleFolder, oldMacPackId + '_ext.sty')
oldTexExtFile = os.path.join(self.local.projTexFolder, oldMacPackId + '_ext.tex')
oldTexPreStyExtFile = os.path.join(self.local.projTexFolder, oldMacPackId + '_preSty-ext.tex')
newStyExtFile = os.path.join(self.local.projStyleFolder, macPackId + '_ext.sty')
newTexExtFile = os.path.join(self.local.projTexFolder, macPackId + '_ext.tex')
newTexPreStyExtFile = os.path.join(self.local.projTexFolder, macPackId + '_preSty-ext.tex')
# By default, we protect any existing versions
if os.path.exists(newStyExtFile) :
os.remove(oldStyExtFile)
else :
self.tools.renameFile(oldStyExtFile, newStyExtFile)
if os.path.exists(newTexExtFile) :
os.remove(oldTexExtFile)
else :
self.tools.renameFile(oldTexExtFile, newTexExtFile)
if os.path.exists(newTexPreStyExtFile) :
os.remove(oldTexPreStyExtFile)
else :
self.tools.renameFile(oldTexPreStyExtFile, newTexPreStyExtFile)
# Remove un-needed sty and tex files from the newMacDir to
# avoid confusion. The ext files never are updated because
# they could contain custom project code that we don't want
# to loose in an update.
for f in self.getMacStyExtFiles(macPackId) :
source = os.path.join(newMacDir, f)
if os.path.exists(source) :
os.remove(source)
for f in self.getMacTexExtFiles(macPackId) :
source = os.path.join(newMacDir, f)
if os.path.exists(source) :
os.remove(source)
# Remove the old macPack folder
shutil.rmtree(oldMacDir)
# Merge new settings into old section (change name to new ID)
# When updating, we are assuming the new macro is in the same
# family as the old one. As such, settings should be almost
# identical, but in case new settings are being added, we will
# merge them in now.
oldConfSettings = self.macroConfig['Macros'][oldMacPackId]
newConfSettings = self.tools.getXMLSettings(confXml)
# Now merge
newConfSettings.merge(oldConfSettings)
# Inject the new section
# self.tools.buildConfSection(self.macroConfig, macPackId)
self.macroConfig['Macros'][macPackId] = newConfSettings.dict()
# Delete the old section
del self.macroConfig['Macros'][oldMacPackId]
# Save the changes
self.tools.writeConfFile(self.macroConfig)
# Assuming everything went well we will change the macPackID on the cType
self.projectConfig['CompTypes'][self.cType.capitalize()]['macroPackage'] = macPackId
self.tools.writeConfFile(self.projectConfig)
# Report success
self.log.writeToLog(self.errorCodes['3600'], [self.cType.capitalize(), macPackId])
return True
# But if the install fails everything stays the same and we report
else :
self.log.writeToLog(self.errorCodes['3650'], [macPackId])
return False
def installMacPackOnly (self, source) :
'''Install the new macro package but only that.'''
# import pdb; pdb.set_trace()
if self.tools.pkgExtract(source, self.local.projMacroFolder, self.local.macroConfXmlFile) :
return True
else :
self.log.writeToLog(self.errorCodes['3200'], [self.tools.fName(source)])
return False
示例2: Macro
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import renameFile [as 別名]
#.........這裏部分代碼省略.........
macPackId = self.getMacPackIdFromSource(source)
confXml = os.path.join(self.local.projMacroFolder, macPackId, macPackId + ".xml")
oldMacPackId = self.projectConfig["CompTypes"][self.cType.capitalize()]["macroPackage"]
oldMacDir = os.path.join(self.local.projMacroFolder, oldMacPackId)
newMacDir = os.path.join(self.local.projMacroFolder, macPackId)
# Install the new macPack (but use the old settings)
if self.installMacPackOnly(source):
# The current macro system must have a "master" style file.
# This is a version of the ParaText style file. Because
# an update might include an update to the style file,
# we need to copy that from the macro folder to the Style
# folder. We will do that now. The name of the file should
# be the macPackId + ".sty", in theory.
srcStyleFile = os.path.join(self.local.projMacroFolder, macPackId, macPackId + ".sty")
oldStyleFile = os.path.join(self.local.projStyleFolder, oldMacPackId + ".sty")
newStyleFile = os.path.join(self.local.projStyleFolder, macPackId + ".sty")
# Unlock the old one so it can be deleted.
self.tools.makeExecutable(oldStyleFile)
self.tools.removeFile(oldStyleFile)
# Now copy in the new one.
shutil.copy(srcStyleFile, newStyleFile)
# The style file should never be edited by the user, relock it
self.tools.makeReadOnly(newStyleFile)
# Update exsisting extention file names. We never want to loose
# any settings that the user may have added to the extention
# files so we will rename the existing files to have the
# new ID otherwise the system will not find them at render time.
oldStyExtFile = os.path.join(self.local.projStyleFolder, oldMacPackId + "_ext.sty")
oldTexExtFile = os.path.join(self.local.projTexFolder, oldMacPackId + "_ext.tex")
oldTexPreStyExtFile = os.path.join(self.local.projTexFolder, oldMacPackId + "_preSty-ext.tex")
newStyExtFile = os.path.join(self.local.projStyleFolder, macPackId + "_ext.sty")
newTexExtFile = os.path.join(self.local.projTexFolder, macPackId + "_ext.tex")
newTexPreStyExtFile = os.path.join(self.local.projTexFolder, macPackId + "_preSty-ext.tex")
# By default, we protect any existing versions
if os.path.exists(newStyExtFile):
os.remove(oldStyExtFile)
else:
self.tools.renameFile(oldStyExtFile, newStyExtFile)
if os.path.exists(newTexExtFile):
os.remove(oldTexExtFile)
else:
self.tools.renameFile(oldTexExtFile, newTexExtFile)
if os.path.exists(newTexPreStyExtFile):
os.remove(oldTexPreStyExtFile)
else:
self.tools.renameFile(oldTexPreStyExtFile, newTexPreStyExtFile)
# Remove un-needed sty and tex files from the newMacDir to
# avoid confusion. The ext files never are updated because
# they could contain custom project code that we don't want
# to loose in an update.
for f in self.getMacStyExtFiles(macPackId):
source = os.path.join(newMacDir, f)
if os.path.exists(source):
os.remove(source)
for f in self.getMacTexExtFiles(macPackId):
source = os.path.join(newMacDir, f)
if os.path.exists(source):
os.remove(source)
# Remove the old macPack folder
shutil.rmtree(oldMacDir)
# Merge new settings into old section (change name to new ID)
# When updating, we are assuming the new macro is in the same
# family as the old one. As such, settings should be almost
# identical, but in case new settings are being added, we will
# merge them in now.
oldConfSettings = self.macroConfig["Macros"][oldMacPackId]
newConfSettings = self.tools.getXMLSettings(confXml)
# Now merge
newConfSettings.merge(oldConfSettings)
# Inject the new section
# self.tools.buildConfSection(self.macroConfig, macPackId)
self.macroConfig["Macros"][macPackId] = newConfSettings.dict()
# Delete the old section
del self.macroConfig["Macros"][oldMacPackId]
# Save the changes
self.tools.writeConfFile(self.macroConfig)
# Assuming everything went well we will change the macPackID on the cType
self.projectConfig["CompTypes"][self.cType.capitalize()]["macroPackage"] = macPackId
self.tools.writeConfFile(self.projectConfig)
# Report success
self.log.writeToLog(self.errorCodes["3600"], [self.cType.capitalize(), macPackId])
return True
# But if the install fails everything stays the same and we report
else:
self.log.writeToLog(self.errorCodes["3650"], [macPackId])
return False
def installMacPackOnly(self, source):
"""Install the new macro package but only that."""
# import pdb; pdb.set_trace()
if self.tools.pkgExtract(source, self.local.projMacroFolder, self.local.macroConfXmlFile):
return True
else:
self.log.writeToLog(self.errorCodes["3200"], [self.tools.fName(source)])
return False