本文整理汇总了Python中exe.engine.path.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateIdevices
def updateIdevices(self):
"""
Update new style HTML/Javascript idevices in user directory.
Copy only when the files are newer
"""
idevice_src_dir=self.webDir/'templates'/'idevices'
idevice_dst_dir=self.configDir/"idevices"
for dir, subdirs, files in os.walk(idevice_src_dir):
reldirpath = idevice_src_dir.relpathto(dir)
for file in files:
dst_file = idevice_dst_dir/reldirpath/file
src_file = Path(dir)/file
src_mtime = src_file.mtime
if not dst_file.exists() or src_mtime > dst_file.mtime:
#check dir
if not dst_file.dirname().isdir():
dst_file.dirname().makedirs()
if file == "idevice.xml" and dst_file.exists():
#We need to update the file whilst preserving if it's visible or not....
dst_xml = etree.parse(dst_file).getroot()
ns = dst_xml.nsmap.get(None)
visible_val = dst_xml.find(".//{%s}visible" % ns).text
src_xml = etree.parse(src_file)
src_xml.find(".//{%s}visible" % ns).text = visible_val
dst_fd = open(dst_file, "w")
dst_fd.write(etree.tostring(src_xml, encoding = "UTF-8", pretty_print = True))
dst_fd.flush()
dst_fd.close()
else:
src_file.copy(dst_file)
示例2: handleSavePackage
def handleSavePackage(self, client, filename=None, onDone=None):
"""
Save the current package
'filename' is the filename to save the package to
'onDone' will be evaled after saving instead or redirecting
to the new location (in cases of package name changes).
(This is used where the user goes file|open when their
package is changed and needs saving)
"""
filename = Path(filename)
saveDir = filename.dirname()
if saveDir and not saveDir.isdir():
client.alert(_(u'Cannot access directory named ') + unicode(saveDir) + _(u'. Please use ASCII names.'))
return
oldName = self.package.name
# If the script is not passing a filename to us,
# Then use the last filename that the package was loaded from/saved to
if not filename:
filename = self.package.filename
assert filename, 'Somehow save was called without a filename on a package that has no default filename.'
# Add the extension if its not already there and give message if not saved
filename = self.b4save(client, filename, '.elp', _(u'SAVE FAILED!'))
try:
self.package.save(filename) # This can change the package name
except Exception, e:
client.alert(_('SAVE FAILED!\n%s' % str(e)))
raise
示例3: setUp
def setUp(self):
"""
Creates an application and
almost launches it.
"""
# Make whatever config class that application uses only look for our
# Set up our customised config file
logFileName = Path('tmp/app data/test.conf')
sys.argv[0] = 'exe/exe'
Config._getConfigPathOptions = lambda s: [logFileName]
if not logFileName.dirname().exists():
logFileName.dirname().makedirs()
confParser = ConfigParser()
self._setupConfigFile(confParser)
confParser.write(logFileName)
# Start up the app and friends
if G.application is None:
G.application = Application()
self.app = G.application
G.application = self.app
self.app.loadConfiguration()
self.app.preLaunch()
self.client = FakeClient()
self.package = Package('temp')
self.session = FakeSession()
self.app.webServer.root.bindNewPackage(self.package, self.session)
self.mainpage = self.app.webServer.root.mainpages[self.session.uid]['temp']
self.mainpage.idevicePane.client = self.client
示例4: exportSinglePage
def exportSinglePage(self, client, filename, webDir, stylesDir):
"""
Export 'client' to a single web page,
'webDir' is just read from config.webDir
'stylesDir' is where to copy the style sheet information from
"""
imagesDir = webDir.joinpath('images')
scriptsDir = webDir.joinpath('scripts')
templatesDir = webDir.joinpath('templates')
filename = Path(filename)
if filename.basename() != self.package.name:
filename /= self.package.name
if not filename.exists():
filename.makedirs()
elif not filename.isdir():
client.alert(_(u'Filename %s is a file, cannot replace it') %
filename)
log.error("Couldn't export web page: "+
"Filename %s is a file, cannot replace it" % filename)
return
else:
try:
filename.rmtree()
filename.mkdir()
except Exception, e:
client.alert(_('There was an error in the export:\n%s') % str(e))
return
示例5: render_POST
def render_POST(self, request):
"""
function replaced by nevow_clientToServerEvent to avoid POST message
"""
log.debug("render_POST " + repr(request.args))
data = {}
try:
locale = request.args['locale'][0]
self.config.locale = locale
self.config.locales[locale].install(unicode=True)
self.config.configParser.set('user', 'locale', locale)
internalAnchors = request.args['internalAnchors'][0]
self.config.internalAnchors = internalAnchors
self.config.configParser.set('user', 'internalAnchors', internalAnchors)
browser = request.args['browser'][0]
if browser == "None":
browser = None
try:
self.config.browser = mywebbrowser.get(browser)
except Exception as e:
browser_path = Path(browser)
if browser_path.exists():
mywebbrowser.register('custom-browser' , None, mywebbrowser.BackgroundBrowser(browser_path.abspath()), -1)
self.config.browser = mywebbrowser.get('custom-browser')
else:
raise e
self.config.configParser.set('system', 'browser', browser)
showWizardOnStart = request.args['showWizardOnStart'][0]
self.config.showWizardOnStart = showWizardOnStart
self.config.configParser.set('user', 'showWizardOnStart', showWizardOnStart)
except Exception as e:
log.exception(e)
return json.dumps({'success': False, 'errorMessage': _("Failed to save preferences wizard")})
return json.dumps({'success': True, 'data': data})
示例6: testUpgradeTo0_20
def testUpgradeTo0_20(self):
"""
Creates a package similar to what 0.19 would
and tests if it upgrades ok
"""
fn = Path('0.19 resources upgrade test.elp')
assert fn.isfile() or fn.islink()
package = self.package.__class__.load(fn)
assert hasattr(package, 'resources')
assert len(package.resources) == 8, len(package.resources)
for checksum, resources in package.resources.items():
storageNames = []
userNames = []
for res in resources:
storageNames.append(res.storageName)
userNames.append(res.userName)
assert len(set(storageNames)) == 1, 'Two identical resources have different storage names:\n%s' % storageNames
allResourceNames = []
for reses in package.resources.values():
allResourceNames.append(reses[0].storageName)
filenames = [path.basename() for path in package.resourceDir.files()]
withoutDups = set(filenames) - set(allResourceNames)
assert withoutDups == set([]), "Duplicate files weren't deleted %s" % withoutDups
assert len(filenames) == len(allResourceNames)
assert len(filenames) > 0, 'All resources have been deleted!'
示例7: handleExport
def handleExport(self, client, exportType, filename):
"""
Called by js.
Exports the current package to one of the above formats
'exportType' can be one of 'singlePage' 'webSite' 'zipFile'
'textFile' or 'scorm'
'filename' is a file for scorm pages, and a directory for websites
"""
webDir = Path(self.config.webDir)
stylesDir = webDir.joinpath('style', self.package.style)
exportDir = Path(filename).dirname()
if exportDir and not exportDir.exists():
client.alert(_(u'Cannot access directory named ') +
unicode(exportDir) +
_(u'. Please use ASCII names.'))
return
if exportType == 'singlePage':
self.exportSinglePage(client, filename, webDir, stylesDir)
elif exportType == 'webSite':
self.exportWebSite(client, filename, stylesDir)
elif exportType == 'zipFile':
self.exportWebZip(client, filename, stylesDir)
elif exportType == 'textFile':
self.exportText(client, filename)
elif exportType == "scorm":
self.exportScorm(client, filename, stylesDir, "scorm1.2")
elif exportType == "scorm2004":
self.exportScorm(client, filename, stylesDir, "scorm2004")
else:
self.exportIMS(client, filename, stylesDir)
示例8: loadSettings
def loadSettings(self):
"""
Loads the settings from the exe.conf file.
Overrides the defaults set in __init__
"""
def defVal(dummy, option):
"""If something is not in the config file, just use the default in
'self'"""
return getattr(self, option)
self.configParser.defaultValue = defVal
self.upgradeFile()
if self.configParser.has_section('system'):
system = self.configParser.system
self.webDir = Path(system.webDir)
self.xulDir = Path(system.xulDir)
self.localeDir = Path(system.localeDir)
self.port = int(system.port)
self.browserPath = Path(system.browserPath)
self.dataDir = Path(system.dataDir)
self.configDir = Path(system.configDir)
if not self.dataDir.isdir():
self.dataDir = tempfile.gettempdir()
self.webDir = self.webDir.expand().abspath()
if not self.configDir.exists():
self.configDir.mkdir()
if self.configParser.has_section('user'):
if self.configParser.user.has_option('locale'):
self.locale = self.configParser.user.locale
self.recentProjects = []
if self.configParser.has_section('recent_projects'):
recentProjectsSection = self.configParser.recent_projects
for key, path in recentProjectsSection.items():
self.recentProjects.append(path)
self.locale = chooseDefaultLocale(self.localeDir)
示例9: setFlash
def setFlash(self, flashPath):
"""
Store the image in the package
Needs to be in a package to work.
"""
log.debug(u"setFlash "+unicode(flashPath))
resourceFile = Path(flashPath)
assert(self.idevice.parentNode,
'Flash '+self.idevice.id+' has no parentNode')
assert(self.idevice.parentNode.package,
'iDevice '+self.idevice.parentNode.id+' has no package')
if resourceFile.isfile():
if self.flashResource:
self.flashResource.delete()
self.idevice.userResources.remove(self.flashResource)
try:
flvDic = FLVReader(resourceFile)
self.height = flvDic["height"] +30
self.width = flvDic["width"]
self.flashResource = Resource(self.idevice.parentNode.package,
resourceFile)
self.idevice.userResources.append(self.flashResource)
except AssertionError:
log.error('File %s is not a flash movie' % resourceFile)
else:
log.error('File %s is not a file' % resourceFile)
示例10: handleSavePackage
def handleSavePackage(self, client, filename=None, onDone=None):
"""
Save the current package
'filename' is the filename to save the package to
'onDone' will be evaled after saving instead or redirecting
to the new location (in cases of package name changes).
(This is used where the user goes file|open when their
package is changed and needs saving)
"""
filename = Path(filename)
saveDir = filename.dirname()
if saveDir and not saveDir.exists():
client.alert(_(u'Cannot access directory named ') +
unicode(saveDir) +
_(u'. Please use ASCII names.'))
return
oldName = self.package.name
if not filename:
filename = self.package.filename
assert (filename,
('Somehow save was called without a filename '
'on a package that has no default filename.'))
if not filename.lower().endswith('.elp'):
filename += '.elp'
self.package.save(filename) # This can change the package name
client.alert(_(u'Package saved to: %s' % filename))
if onDone:
client.sendScript(onDone)
elif self.package.name != oldName:
self.webServer.root.putChild(self.package.name, self)
log.info('Package saved, redirecting client to /%s'
% self.package.name)
client.sendScript('top.location = "/%s"' % \
self.package.name.encode('utf8'))
示例11: exportWebSite
def exportWebSite(self, client, filename, webDir, stylesDir):
"""
Export 'client' to a web site,
'webDir' is just read from config.webDir
'stylesDir' is where to copy the style sheet information from
"""
imagesDir = webDir.joinpath('images')
scriptsDir = webDir.joinpath('scripts')
templatesDir = webDir.joinpath('templates')
filename = Path(filename)
if filename.basename() != self.package.name:
filename /= self.package.name
if not filename.exists():
filename.makedirs()
elif not filename.isdir():
client.alert(_(u'Filename %s is a file, cannot replace it') %
filename)
log.error("Couldn't export web page: "+
"Filename %s is a file, cannot replace it" % filename)
return
else:
filename.rmtree()
filename.mkdir()
websiteExport = WebsiteExport(stylesDir, filename,
imagesDir, scriptsDir, templatesDir)
websiteExport.export(self.package)
self._startFile(filename)
示例12: launchBrowser
def launchBrowser(config, packageName):
"""
Launch the configured webbrowser for this platform
"""
url = u'%s/%s' % (G.application.exeAppUri, quote(packageName))
log.info(u"url " + url)
dfbrw=mywebbrowser.get()
withdefaultbrowser=True
if config.browser!=None:
try:
config.browser = mywebbrowser.get(config.browser)
if not config.browser.open(url):
log.error("Unable to open defined browser: " + config.browser.name)
withdefaultbrowser = True
else:
withdefaultbrowser = False
except:
browser_path = Path(config.browser)
if browser_path.exists():
log.info(u"path browser " + browser_path.abspath())
mywebbrowser.register("custom-browser" , None, mywebbrowser.BackgroundBrowser(browser_path.abspath()), -1)
config.browser = mywebbrowser.get("custom-browser")
if not config.browser.open(url):
log.error("Unable to open custom defined browser: " + browser_path.abspath())
withdefaultbrowser=True
else:
withdefaultbrowser=False
if withdefaultbrowser:
config.browser = dfbrw
config.browser.open(url, new=0, autoraise=True)
if hasattr(config.browser, "name"):
log.info(u"Defined Browser: " + config.browser.name)
示例13: testUpgradeAppDir
def testUpgradeAppDir(self):
"""
Tests that config files with
'appDataDir' are upgraded to 'configDir'
"""
# Write the old style config file
configPath = Path(u'test.exe.conf')
if configPath.exists():
configPath.remove()
oldParser = ConfigParser()
system = oldParser.addSection('system')
system.appDataDir = 'my old app data dir'
oldParser.write(configPath)
del system
del oldParser
# Make the config instance load it
Config._getConfigPathOptions = lambda self: ['test.exe.conf']
myconfig = Config()
myconfig.loadSettings()
# Check if it reads the old value into the new variable
assert not hasattr(myconfig, 'appDataDir')
self.assertEquals(myconfig.configPath, 'test.exe.conf')
self.assertEquals(myconfig.configDir, 'my old app data dir')
# Check if it has upgraded the file and added in some nice default values
newParser = ConfigParser()
newParser.read(configPath)
self.assertEquals(newParser.system.configDir, 'my old app data dir')
示例14: StandaloneConfig
class StandaloneConfig(Config):
"""
The StandaloneConfig overrides the Config class with ready-to-run specific
configuration
"""
def _overrideDefaultVals(self):
"""
Setup with our default settings
"""
self.exePath = Path(sys.argv[0])
if self.exePath.isfile():
self.exePath = self.exePath.dirname()
exePath = self.exePath
self.webDir = exePath
self.dataDir = exePath/'packages'
if not self.dataDir.exists():
self.dataDir.makedirs()
self.configDir = exePath/'config'
self.localeDir = exePath/'locale'
self.xulrunnerPath = exePath/'xulrunner/xulrunner'
self.styles = []
self.browserPath = exePath/'firefox'/'firefox.exe'
def _getConfigPathOptions(self):
"""
Returns the best places for a linux config file
"""
return [self.configDir/'exe.conf']
示例15: handleExternalResources
def handleExternalResources(self, html):
html_content_lower = html.lower()
start_index = 0
start_index = self._findNextTagStart(html_content_lower, start_index, ['img'])
while start_index != -1:
res_src = self._getSrcForTag(html, start_index)
if res_src is not None and res_src.startswith("http://"):
new_file_basename = self.url2ascii(res_src)
new_file_name = str(self.workingDir/new_file_basename)
new_file_path = Path(self.workingDir/new_file_basename)
if new_file_path.exists() is False:
urllib.urlretrieve(res_src, new_file_name)
old_length = len(html)
html = html.replace(res_src, new_file_name)
html_content_lower = html.lower()
new_length = len(html)
length_difference = old_length - new_length
start_index += length_difference
end_tag_index = html_content_lower.find(">", start_index);
start_index = self._findNextTagStart(html_content_lower,end_tag_index , ['img'])
return html