本文整理匯總了Python中rapuma.core.tools.Tools.pkgExtract方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.pkgExtract方法的具體用法?Python Tools.pkgExtract怎麽用?Python Tools.pkgExtract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.pkgExtract方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Macro
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import pkgExtract [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 pkgExtract [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
示例3: ProjFont
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import pkgExtract [as 別名]
#.........這裏部分代碼省略.........
if not os.path.isfile(metaDataSource) :
self.log.writeToLog(self.errorCodes['1240'], [fontId + '.xml', 'proj_font.recordFont():1240'])
# Build the Fonts section in the config (if needed)
self.tools.buildConfSection(self.fontConfig, 'Fonts')
# (Re)Inject the font info into the macPack config file.
fInfo = self.tools.getXMLSettings(metaDataSource)
self.fontConfig['Fonts'][fontId] = fInfo.dict()
# Save the settings now
self.tools.writeConfFile(self.fontConfig)
# If a component type was specified, record that as well
if cType :
self.projectConfig['CompTypes'][cType.capitalize()]['fontName'] = fontId
self.tools.writeConfFile(self.projectConfig)
return True
def copyInFont (self, source) :
'''Copy a font into a project. The font is bundled with other
necessary components in a .zip file. If the font folder is
already there we assume there is a font there and we do not
proceed. The user will be prompted to remove the old one first.'''
fontId = self.getFontIdFromSource(source)
confXml = os.path.join(self.local.projFontFolder, fontId, fontId + '.xml')
if not os.path.isfile(source) :
self.log.writeToLog(self.errorCodes['1220'], [source])
# Install new copy
if self.tools.pkgExtract(source, self.local.projFontFolder, confXml) :
self.log.writeToLog(self.errorCodes['1260'], [self.tools.fName(source)])
return True
else :
self.log.writeToLog(self.errorCodes['1265'], [fontId])
return False
def addFont (self, source, cType=None) :
'''It is a three step process to install a font. This will both
copy in a font and record it in one call. Do not try to
install a substitute font. Path is assumed to exsist and contains
the file name too.'''
# import pdb; pdb.set_trace()
fontId = self.getFontIdFromSource(source)
# Check for existance, never copy over
if self.isFont(fontId) :
self.log.writeToLog(self.errorCodes['1250'], [fontId])
# Now install and record
if self.copyInFont(source) and self.recordFont(fontId, cType) :
self.log.writeToLog(self.errorCodes['1235'], [fontId])
return True
else :
self.log.writeToLog(self.errorCodes['1280'], [fontId])
return False
def updateFontPack (self, source, cType=None) :
'''Update a font package but do not change any of the existing
settings. If there are setting issues (changes) it would be
best to remove, then reinstall. A potential confusion point