本文整理汇总了Python中exe.engine.path.Path.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Path.exists方法的具体用法?Python Path.exists怎么用?Python Path.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.path.Path
的用法示例。
在下文中一共展示了Path.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def main():
if len(sys.argv) < 2:
print 'Usage: %s [version] [--install] [--local|username password]' % sys.argv[0]
print 'Where [version] is the branch you want to checkout'
print 'and username and password are for your eduforge account'
print 'Eg. %s 0.7 --local' % sys.argv[0]
else:
version = sys.argv[1]
branch = 'http://exe.cfdl.auckland.ac.nz/svn/exe/branches/%s' % version
origDir = Path(sys.argv[0]).abspath().dirname()
tmp = TempDirPath()
os.chdir(tmp)
os.system('svn export %s exe' % branch)
(origDir/'../../exe/webui/firefox').copytree(tmp/'exe/exe/webui/firefox')
os.chdir(tmp/'exe')
tarball = Path('../exe-%s-source.tgz' % version).abspath()
os.system('tar czf %s *' % tarball)
os.chdir(tmp)
if '--local' not in sys.argv:
try:
from paramiko import Transport
except ImportError:
print 'To upload you need to install paramiko python library from:'
print 'http://www.lag.net/paramiko'
sys.exit(2)
from socket import socket, gethostbyname
s = socket()
s.connect((gethostbyname('shell.eduforge.org'), 22))
t = Transport(s)
t.connect()
t.auth_password(sys.argv[-2], sys.argv[-1])
f = t.open_sftp_client()
f.chdir('/home/pub/exe')
f.put(tarball.encode('utf8'), tarball.basename().encode('utf8'))
if os.getuid() == 0:
tarball.copyfile('/usr/portage/distfiles/' + tarball.basename())
os.chdir(tmp/'exe/installs/gentoo')
newEbuildFilename = Path('exe-%s.ebuild' % version).abspath()
if not newEbuildFilename.exists():
Path('exe-0.7.ebuild').copy(newEbuildFilename)
if os.getuid() == 0:
ebuildDir = Path('/usr/local/portage/dev-python/exe')
if ebuildDir.exists():
ebuildDir.rmtree()
ebuildDir.makedirs()
os.chdir(ebuildDir)
newEbuildFilename.copy(ebuildDir)
filesDir = ebuildDir/'files'
filesDir.makedirs()
Path(tmp/'exe/installs/gentoo/all-config.patch').copy(filesDir)
if '--local' not in sys.argv:
oldTarball = Path('/usr/portage/distfiles/')/tarball.basename()
if oldTarball.exists():
oldTarball.remove()
os.environ['GENTOO_MIRRORS']=''
os.system('ebuild %s fetch' % newEbuildFilename.basename())
os.system('ebuild %s manifest' % newEbuildFilename.basename())
os.system('ebuild %s digest' % newEbuildFilename.basename())
if '--install' in sys.argv:
os.system('ebuild %s install' % newEbuildFilename.basename())
示例2: do_export
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def do_export(self, inputf, outputf):
if hasattr(self, 'export_' + self.options["export"]):
LOG.debug("Exporting to type %s, in: %s, out: %s, overwrite: %s" \
% (self.options["export"], inputf, outputf, str(self.options["overwrite"])))
if not outputf:
if self.options["export"] in ('website', 'singlepage'):
outputf = inputf.rsplit(".elp")[0]
else:
outputf = inputf + self.extensions[self.options["export"]]
outputfp = Path(outputf)
if outputfp.exists() and not self.options["overwrite"]:
error = _(u'"%s" already exists.\nPlease try again \
with a different filename') % outputf
raise Exception(error.encode(sys.stdout.encoding))
else:
if outputfp.exists() and self.options["overwrite"]:
if outputfp.isdir():
for filen in outputfp.walkfiles():
filen.remove()
outputfp.rmdir()
else:
outputfp.remove()
pkg = Package.load(inputf)
LOG.debug("Package %s loaded" % (inputf))
if not pkg:
error = _(u"Invalid input package")
raise Exception(error.encode(sys.stdout.encoding))
self.styles_dir = self.web_dir.joinpath('style', pkg.style)
LOG.debug("Styles dir: %s" % (self.styles_dir))
getattr(self, 'export_' + self.options["export"])(pkg, outputf)
return outputf
else:
raise Exception(_(u"Export format not implemented")\
.encode(sys.stdout.encoding))
示例3: renderEdit
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def renderEdit(self, style):
"""
Returns an XHTML string with the form element for editing this block
"""
html = u'<div>'
html += '<span class="js-idevice-title-label">'
html += '<label for="title'+self.id+'">'+_('Title')+':</label> '
html += common.elementInstruc(_('The title and the icon are not required. If you leave them empty the iDevice will have no emphasis.'))
html += '</span>'
html += common.hiddenField("iconiDevice" + self.id, self.idevice.icon)
html += u'<a class="js-show-icon-panel-button" href="javascript:showMessageBox(\'iconpanel\');" title="%s"><img src="/images/stock-insert-image.png" alt="%s" width="16" height="16" /></a>' % (_('Select an icon'),_('Choose an Image'))
# Get icon source (if it exists)
icon = self.idevice.icon
icon_exists = False
if icon != '':
idevice_icon = Path(G.application.config.stylesDir / style / 'icon_' + self.idevice.icon + '.gif')
if idevice_icon.exists():
icon_exists = True
else:
idevice_icon = Path(G.application.config.stylesDir/style/"icon_" + self.idevice.icon + ".png")
if idevice_icon.exists():
icon_exists = True
# Icon HTML element
html += u'<img class="js-idevide-icon-preview" name="iconiDevice%s" id="iconiDevice"' % (self.id)
if icon_exists:
html += u' src="/style/%s/icon_%s%s"' % (style, icon, idevice_icon.ext)
else:
html += u' src="/images/empty.gif"'
html += u'/>'
# Delete button
html += u'<a href="javascript:deleteIcon(%s);" id="deleteIcon%s" class="deleteIcon" title="%s"' % (self.id, self.id, _('Delete'))
# If the icon doesn't exists
if not icon_exists:
html += u' style="display: none;"'
html += u'>'
html += u'<img class="js-delete-icon" alt="%s" src="%s"/>' % (_('Delete'), '/images/stock-delete.png')
html += u'</a>'
html += common.textInput("title" + self.id, self.idevice.title)
html += u'<div class="js-icon-panel-container">'
html += u'<div id="iconpaneltitle">%s</div>' % _("Icons")
html += u'<div id="iconpanelcontent">'
html += self.__renderIcons(style)
html += u'</div>'
html += u"</div>"
for element in self.elements:
html += element.renderEdit()
html += self.renderEditButtons()
html += u"</div>"
return html
示例4: doTest
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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()
示例5: handleExternalResources
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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
示例6: exportWebSite
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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)
示例7: launchBrowser
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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)
示例8: _setupConfigFile
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def _setupConfigFile(self, configParser):
"""
Override this to setup any customised config
settings
"""
# Set up the system section
system = configParser.addSection('system')
system.exePath = 'exe/exe'
system.exeDir = 'exe'
system.webDir = 'exe/webui'
system.localeDir = 'exe/locale'
system.configDir = 'tmp'
system.port = 8081
# Make a temporary dir where we can save packages and exports etc
tmpDir = Path('tmp')
if not tmpDir.exists():
tmpDir.mkdir()
dataDir = tmpDir / 'data'
if not dataDir.exists():
dataDir.mkdir()
system.dataDir = dataDir
system.browserPath = 'not really used in tests so far'
# Setup the logging section
logging = configParser.addSection('logging')
logging.root = 'DEBUG'
示例9: testUpgradeAppDir
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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')
示例10: makeXulPO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def makeXulPO(applicationDirectoryPath, applicationDomain=None, verbose=0):
"""Searches through xul files and appends to messages.pot"""
if verbose:
print "Importing xul templates..."
path = Path(applicationDirectoryPath)
messages = pot2dict('exe/locale/messages.pot')
messageCommentTemplate = '\n#: %s:%s\nmsgid "'
seq = len(messages)
skipPaths = (
applicationDirectoryPath/'exe/webui/firefox',
)
for fn in path.walkfiles():
if fn.ext.lower() == '.xul':
for skipPath in skipPaths:
if fn.startswith(skipPath):
print 'IGNORING', fn
break
else:
if verbose:
print "template: ", fn
reader = Sax2.Reader()
doc = reader.fromStream(file(fn, 'rb'))
xul2dict(doc, messages, seq, fn.relpath())
pot = Path('exe/locale/messages.pot')
if pot.exists():
pot.remove()
pot.touch()
dict2pot(messages, 'exe/locale/messages.pot')
示例11: exportSinglePage
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def exportSinglePage(self, client, filename, webDir, stylesDir, printFlag):
"""
Export 'client' to a single web page,
'webDir' is just read from config.webDir
'stylesDir' is where to copy the style sheet information from
'printFlag' indicates whether or not this is for print (and whatever else that might mean)
"""
try:
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:
client.alert(_(u'Folder name %s already exists. '
'Please choose another one or delete existing one then try again.') % filename)
return
singlePageExport = SinglePageExport(stylesDir, filename, imagesDir, scriptsDir, templatesDir)
singlePageExport.export(self.package, printFlag)
except Exception, e:
client.alert(_('SAVE FAILED!\n%s' % str(e)))
raise
示例12: exportIpod
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def exportIpod(self, client, filename):
"""
Export 'client' to an iPod Notes folder tree
'webDir' is just read from config.webDir
"""
try:
# filename is a directory where we will export the notes to
# We assume that the user knows what they are doing
# and don't check if the directory is already full or not
# and we just overwrite what's already there
filename = Path(filename)
# Append the package name to the folder path if necessary
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:
client.alert(_(u'Folder name %s already exists. '
'Please choose another one or delete existing one then try again.') % filename)
return
# Now do the export
ipodExport = IpodExport(self.config, filename)
ipodExport.export(self.package)
except Exception, e:
client.alert(_('EXPORT FAILED!\n%s') % str(e))
raise
示例13: handleExport
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
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)
示例14: makeMO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def makeMO(applicationDirectoryPath, targetDir=None, applicationDomain=None, verbose=0, forceEnglish=0):
"""Compile the Portable Object files into the Machine Object stored in the right location.
makeMO converts all translated language-specific PO files located inside
the application directory into the binary .MO files stored inside the
LC_MESSAGES sub-directory for the found locale files.
makeMO searches for all files that have a name of the form 'app_xx.po'
inside the application directory specified by the first argument. The
'app' is the application domain name (that can be specified by the
applicationDomain argument or is taken from the directory name). The 'xx'
corresponds to one of the ISO 639 two-letter language codes.
makeMo stores the resulting files inside a sub-directory of `targetDir`
called xx/LC_MESSAGES where 'xx' corresponds to the 2-letter language
code.
"""
if targetDir is None:
targetDir = "exe/locale"
if verbose:
print "Target directory for .mo files is: %s" % targetDir
targetDir = Path(targetDir)
if applicationDomain is None:
applicationName = fileBaseOf(applicationDirectoryPath, withPath=0)
else:
applicationName = applicationDomain
currentDir = os.getcwd()
os.chdir(applicationDirectoryPath)
for filename in targetDir.glob("*_*.po"):
langCode = filename.split("_", 1)[1].split(".", 1)[0]
mo_targetDir = Path("%s/%s/LC_MESSAGES" % (targetDir, langCode))
if not mo_targetDir.exists():
mo_targetDir.makedirs()
cmd = "msgfmt --output-file=%s.mo %s" % (mo_targetDir / applicationName, filename)
if verbose:
print cmd
os.system(cmd)
os.chdir(currentDir)
示例15: makePO
# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import exists [as 别名]
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1) :
"""Build the Portable Object Template file for the application.
makePO builds the .pot file for the application stored inside
a specified directory by running xgettext for all application source
files. It finds the name of all files by looking for a file called 'app.fil'.
If this file does not exists, makePo raises an IOError exception.
By default the application domain (the application
name) is the same as the directory name but it can be overridden by the
'applicationDomain' argument.
makePO always creates a new file called messages.pot. If it finds files
of the form app_xx.po where 'app' is the application name and 'xx' is one
of the ISO 639 two-letter language codes, makePO resynchronizes those
files with the latest extracted strings (now contained in messages.pot).
This process updates all line location number in the language-specific
.po files and may also create new entries for translation (or comment out
some). The .po file is not changed, instead a new file is created with
the .new extension appended to the name of the .po file.
By default the function does not display what it is doing. Set the
verbose argument to 1 to force it to print its commands.
"""
if applicationDomain is None:
applicationName = fileBaseOf(applicationDirectoryPath,withPath=0)
else:
applicationName = applicationDomain
currentDir = os.getcwd()
messages_pot = Path('exe/locale/messages.pot')
# Use xgettext to make the base messages.pot (with header, etc.)
if messages_pot.exists():
messages_pot.remove()
messages_pot.touch()
cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 exe/engine/package.py'
if verbose: print cmd
os.system(cmd)
if not os.path.exists('app.fil'):
raise IOError(2,'No module file: app.fil')
# Steps:
# Use xgettext to parse all application modules
# The following switches are used:
#
# -s : sort output by string content (easier to use when we need to merge several .po files)
# --files-from=app.fil : The list of files is taken from the file: app.fil
# --output= : specifies the name of the output file (using a .pot extension)
cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 %s'
if verbose: print cmd
for fn in open('app.fil'):
print 'Extracting from', fn,
os.system(cmd % fn[:-1])
makeXulPO(applicationDirectoryPath, applicationDomain, verbose)
# Merge new pot with .po files
localeDirs = Path('exe/locale')
for filename in localeDirs.walkfiles('*_*.po'):
cmd = "msgmerge -U --no-wrap %s exe/locale/messages.pot" % filename
if verbose: print cmd
os.system(cmd)