本文整理汇总了Python中exe.engine.path.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:UstadMobile,项目名称:eXePUB,代码行数:31,代码来源:config.py
示例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
开发者ID:giorgil2,项目名称:eXe,代码行数:27,代码来源:mainpage.py
示例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
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:29,代码来源:utils.py
示例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
开发者ID:,项目名称:,代码行数:27,代码来源:
示例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})
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:34,代码来源:loginumcloudpage.py
示例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!'
开发者ID:,项目名称:,代码行数:25,代码来源:
示例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)
开发者ID:,项目名称:,代码行数:30,代码来源:
示例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)
开发者ID:,项目名称:,代码行数:34,代码来源:
示例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)
开发者ID:,项目名称:,代码行数:26,代码来源:
示例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'))
开发者ID:,项目名称:,代码行数:34,代码来源:
示例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)
开发者ID:,项目名称:,代码行数:27,代码来源:
示例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)
开发者ID:Rafav,项目名称:iteexe,代码行数:32,代码来源:browser.py
示例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')
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:27,代码来源:testconfig.py
示例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']
开发者ID:,项目名称:,代码行数:27,代码来源:
示例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
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:25,代码来源:exportmediaconverter.py
示例16: handleExtractPackage
def handleExtractPackage(self, client, filename, existOk):
"""
Create a new package consisting of the current node and export
'existOk' means the user has been informed of existance and ok'd it
"""
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
if not filename.lower().endswith('.elp'):
filename += '.elp'
if Path(filename).exists() and existOk != 'true':
msg = _(u'"%s" already exists.\nPlease try again with a different filename') % filename
client.alert(_(u'EXTRACT FAILED!\n%s' % msg))
return
try:
package = Package(filename.namebase)
package.style = self.package.style
package.author = self.package.author
extractNode = self.package.currentNode.clone()
extractNode.mergeIntoPackage(package)
package.root = package.currentNode = extractNode
package.save(filename)
except Exception, e:
client.alert(_('EXTRACT FAILED!\n%s' % str(e)))
raise
开发者ID:,项目名称:,代码行数:27,代码来源:
示例17: doTest
def doTest(self, ExporterClass):
"""Exports a package with meta data"""
# Load our test package
package = Package.load('testPackage.elp')
# Do the export
outFilename = Path('scormtest.zip')
exporter = ExporterClass(self.app.config,
'../exe/webui/style/default',
outFilename)
exporter.export(package)
# Check that it made a nice zip file
assert outFilename.exists()
# See if the manifest file was created
zipped = ZipFile(outFilename)
filenames = zipped.namelist()
assert 'imsmanifest.xml' in filenames, filenames
self._testManifest(zipped.read('imsmanifest.xml'))
# Test that all the node's html files have been generated
pagenodes = Set([p.node for p in exporter.pages])
othernodes = Set(self._getNodes([], package.root))
assert pagenodes == othernodes
for page in exporter.pages:
self._testPage(page, zipped)
# Clean up
zipped.close()
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:28,代码来源:testexport.py
示例18: __init__
def __init__(self, config, styleDir, filename, prefix="", report=False, skipNavigation=False, ustadMobileMode=False, ustadMobileTestMode=False):
#Added ustadMobileTestMode for Course Test Mode.
"""
'stylesDir' is the directory where we can copy the stylesheets from
'outputDir' is the directory that will be [over]written
with the website
"""
self.config = config
self.imagesDir = config.webDir/"images"
self.scriptsDir = config.webDir/"scripts"
self.cssDir = config.webDir/"css"
self.templatesDir = config.webDir/"templates"
self.stylesDir = Path(styleDir)
self.filename = Path(filename)
self.pages = []
self.prefix = prefix
self.report = report
self.skipNavigation = skipNavigation
self.ustadMobileMode = ustadMobileMode
self.ustadMobileTestMode = ustadMobileTestMode #Added for Course Test Mode
self.styleSecureMode = config.styleSecureMode
self.config = config
self.imagesDir = config.webDir/"images"
self.scriptsDir = config.webDir/"scripts"
self.cssDir = config.webDir/"css"
self.templatesDir = config.webDir/"templates"
self.stylesDir = Path(styleDir)
self.filename = Path(filename)
self.pages = []
self.prefix = prefix
self.report = report
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:34,代码来源:websiteexport.py
示例19: __init__
def __init__(self):
"""
Initialise
"""
self.configPath = None
self.configParser = ConfigParser()
self.exePath = Path(sys.argv[0]).abspath()
self.webDir = self.exePath.dirname()
self.xulDir = self.exePath.dirname()
self.localeDir = self.exePath.dirname() / "locale"
self.port = 51235
self.dataDir = Path(".")
self.configDir = Path(".")
self.browserPath = Path("firefox")
self.locale = chooseDefaultLocale(self.localeDir)
self.styles = []
self._overrideDefaultVals()
self.webDir = Path(self.webDir)
if not (self.webDir / "scripts").isdir() and (self.webDir / "webui").isdir():
self.webDir /= "webui"
self.xulDir = Path(self.xulDir)
if not (self.xulDir / "scripts").isdir() and (self.xulDir / "xului").isdir():
self.xulDir /= "xului"
self.__setConfigPath()
self._writeDefaultConfigFile()
self.loadSettings()
self.setupLogging()
self.loadStyles()
self.loadLocales()
开发者ID:,项目名称:,代码行数:29,代码来源:
示例20: _process
def _process(self, request):
"""
Delegates processing of args to blocks
"""
# Still need to call parent (mainpage.py) process
# because the idevice pane needs to know that new idevices have been
# added/edited..
self.parent.process(request)
if ("action" in request.args and
request.args["action"][0] == u"saveChange"):
log.debug(u"process savachange:::::")
self.package.save()
log.debug(u"package name: " + self.package.name)
for block in self.blocks:
block.process(request)
# now that each block and corresponding elements have been processed,
# it's finally safe to remove any images/etc which made it into
# tinyMCE's previews directory, as they have now had their
# corresponding resources created:
webDir = Path(G.application.tempWebDir)
previewDir = webDir.joinpath('previews')
for root, dirs, files in os.walk(previewDir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
log.debug(u"After authoringPage process" + repr(request.args))
开发者ID:kohnle-lernmodule,项目名称:palama,代码行数:26,代码来源:authoringpage.py
注:本文中的exe.engine.path.Path类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论