本文整理匯總了Python中rapuma.core.tools.Tools.alterFileName方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.alterFileName方法的具體用法?Python Tools.alterFileName怎麽用?Python Tools.alterFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rapuma.core.tools.Tools
的用法示例。
在下文中一共展示了Tools.alterFileName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ProjBackground
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import alterFileName [as 別名]
class ProjBackground (object) :
def __init__(self, pid, gid = None) :
'''Intitate the whole class and create the object.'''
# import pdb; pdb.set_trace()
self.pid = pid
self.gid = gid
self.local = ProjLocal(pid, gid)
self.tools = Tools()
self.proj_config = Config(pid, gid)
self.proj_config.getProjectConfig()
self.proj_config.getLayoutConfig()
self.projectConfig = self.proj_config.projectConfig
self.layoutConfig = self.proj_config.layoutConfig
self.log = ProjLog(pid)
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.projHome = os.path.join(os.environ['RAPUMA_PROJECTS'], self.pid)
self.mmToPx = 72 / 25.4
# For debugging purposes a switch can be set here for verbose
# message output via the terminal
self.debugMode = self.tools.str2bool(self.userConfig['System']['debugging'])
# Log messages for this module
self.errorCodes = {
'0000' : ['MSG', 'Placeholder message'],
'1110' : ['MSG', 'File exsits: [<<1>>]. Use \"force\" to remove it.'],
'1280' : ['ERR', 'Failed to merge background file with command: [<<1>>]. This is the error: [<<2>>]'],
'1290' : ['ERR', 'Failed to convert background file [<<1>>]. Error: [<<2>>] The command was: [<<3>>]'],
'1300' : ['MSG', 'Background merge operation in process, please wait...'],
'1305' : ['MSG', 'Adding document information, please wait...'],
'1310' : ['WRN', 'Failed to add background component: [<<1>>] with error: [<<2>>]'],
'1320' : ['MSG', 'New background created.']
}
###############################################################################
############################### Basic Functions ###############################
###############################################################################
######################## Error Code Block Series = 1000 #######################
###############################################################################
def turnOnBackground (self) :
'''Change the layout config settings to turn on the background.'''
if not self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useBackground']) :
self.layoutConfig['DocumentFeatures']['useBackground'] = True
self.tools.writeConfFile(self.layoutConfig)
def turnOffBackground (self) :
'''Change the layout config settings to turn off the background.'''
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useBackground']) :
self.layoutConfig['DocumentFeatures']['useBackground'] = False
self.tools.writeConfFile(self.layoutConfig)
def turnOnDocInfo (self) :
'''Change the layout config settings to turn on the doc info in the background.'''
if not self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDocInfo']) :
self.layoutConfig['DocumentFeatures']['useDocInfo'] = True
self.tools.writeConfFile(self.layoutConfig)
def turnOffDocInfo (self) :
'''Change the layout config settings to turn off the doc info in the background.'''
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDocInfo']) :
self.layoutConfig['DocumentFeatures']['useDocInfo'] = False
self.tools.writeConfFile(self.layoutConfig)
def addBackground (self, target) :
'''Add a background (watermark) to a rendered PDF file. This will
figure out what the background is to be composed of and create
a master background page. Using force will cause it to be remade.'''
# Do a quick check if the background needs to be remade
# The background normally is not remade if one already exists.
# If one is there, it can be remade if regenerate is set to
# to True. Obviously, if one is not there, it will be made.
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['regenerateBackground']) :
self.createBackground()
else :
# If there isn't one, make it
if not os.path.exists(self.local.backgroundFile) :
self.createBackground()
# Merge target with the project's background file in the Illustraton folder
self.log.writeToLog(self.errorCodes['1300'])
# Create a special name for the file with the background
# Then merge and save it
viewFile = self.tools.alterFileName(target, 'view')
#.........這裏部分代碼省略.........
示例2: ProjDiagnose
# 需要導入模塊: from rapuma.core.tools import Tools [as 別名]
# 或者: from rapuma.core.tools.Tools import alterFileName [as 別名]
class ProjDiagnose (object) :
def __init__(self, pid, gid = None) :
'''Intitate the whole class and create the object.'''
# import pdb; pdb.set_trace()
self.pid = pid
self.gid = gid
self.local = ProjLocal(pid, gid)
self.tools = Tools()
self.proj_config = Config(pid, gid)
self.proj_config.getProjectConfig()
self.proj_config.getLayoutConfig()
self.layoutConfig = self.proj_config.layoutConfig
self.user = UserConfig()
self.userConfig = self.user.userConfig
self.log = ProjLog(pid)
# to [px] is 72/25.4
self.mmToPx = 72 / 25.4
# page width [px]
self.paperPxWidth = round(self.mmToPx * float(self.layoutConfig['PageLayout']['pageWidth']),1)
# page height [px]
self.paperPxHeight = round(self.mmToPx * float(self.layoutConfig['PageLayout']['pageHeight']),1)
# Log messages for this module
self.errorCodes = {
'0000' : ['MSG', 'Placeholder message'],
'1310' : ['WRN', 'Failed to add diagnostic component: [<<1>>] with error: [<<2>>]']
}
###############################################################################
############################### Create Functions ##############################
###############################################################################
######################## Error Code Block Series = 1000 #######################
###############################################################################
def turnOnDiagnostic (self) :
'''Change the layout config settings to turn on the diagnostic layer.'''
if not self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDiagnostic']) :
self.layoutConfig['DocumentFeatures']['useDiagnostic'] = True
self.tools.writeConfFile(self.layoutConfig)
def turnOffDiagnostic (self) :
'''Change the layout config settings to turn off the diagnostic layer.'''
if self.tools.str2bool(self.layoutConfig['DocumentFeatures']['useDiagnostic']) :
self.layoutConfig['DocumentFeatures']['useDiagnostic'] = False
self.tools.writeConfFile(self.layoutConfig)
def addTransparency (self, target, force = False) :
'''Add a transparent layer to a rendered PDF file. This will
add in diagnosing format issues. Using force will cause any
existing layer file to be remade.'''
# Do a quick check if the transparency needs to be remade
# The transparency normally is not remade if one already exists.
# If one is there, it can be remade in two ways, with a force
# or a regenerate command.
if force :
self.createDiagnostic()
elif self.tools.str2bool(self.layoutConfig['DocumentFeatures']['regenerateTransparency']) :
self.createDiagnostic()
else :
# If there isn't one, make it
if not os.path.exists(self.local.diagnosticFile) :
self.createDiagnostic()
# Create a special temp named file for the target
tmpTarget = tempfile.NamedTemporaryFile().name
# Copy the target to the tmpTarget
shutil.copy(target, tmpTarget)
# Overlay the transparency diagnostic file over the tmpTarget
self.tools.mergePdfFilesPdftk(tmpTarget, self.local.diagnosticFile)
# Create a special name for the file with the background
# Then merge and save it
viewFile = self.tools.alterFileName(target, 'view')
# Copy the results back to the target (should be done now)
shutil.copy(tmpTarget, viewFile)
# Not returning a file name would mean it failed
if os.path.exists(viewFile) :
return viewFile
def createDiagnostic (self) :
'''Create a diagnostic transparency (file) that will be
superimposed over the page contents to help diagnose format
issues. This will overwrite any existing transparency file and
will add each recognoized diagnostic type found in the
#.........這裏部分代碼省略.........