本文整理汇总了Python中xpcom.server.UnwrapObject._relativeBasedir方法的典型用法代码示例。如果您正苦于以下问题:Python UnwrapObject._relativeBasedir方法的具体用法?Python UnwrapObject._relativeBasedir怎么用?Python UnwrapObject._relativeBasedir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xpcom.server.UnwrapObject
的用法示例。
在下文中一共展示了UnwrapObject._relativeBasedir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _packageParts
# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import _relativeBasedir [as 别名]
def _packageParts(self, packagePath, partList=None, orig_project=None,
live=0, extradir=1, overwrite=0):
# setup a temporary project file, as we may need to do modifications
# that shoule only be in the packaged version
if packagePath.find('.kpz') == -1:
zipfilename = packagePath+'.kpz'
else:
zipfilename = packagePath
if self.debug:
print "zipfilename [%s]" % zipfilename
if os.path.exists(zipfilename):
if overwrite:
os.unlink(zipfilename)
else:
err = 'A package with the same name already exists at that location.'
self.lastErrorSvc.setLastError(1, err)
raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE, err)
try:
projectName = os.path.splitext(os.path.basename(packagePath))[0]
if orig_project:
newproject = orig_project.clone()
else:
newproject = UnwrapObject(components.classes["@activestate.com/koProject;1"]
.createInstance(components.interfaces.koIProject))
newproject.create()
newproject.live = live
newproject._url = os.path.join(os.path.dirname(zipfilename), 'package.kpf')
tmp_project_localPath = uriparse.URIToLocalPath(newproject._url)
newproject.name = projectName
if self.debug:
print "newproject._url [%s]" % newproject._url
if partList:
# clone parts and add them to the project
self._clonePartList(newproject, partList)
# figure out a base path for all the parts
newproject._relativeBasedir = os.path.commonprefix(newproject._urlmap.keys())
if not newproject._relativeBasedir:
newproject._relativeBasedir = os.path.dirname(newproject._url)
if self.debug:
print "using relative base [%s]" % newproject._relativeBasedir
import zipfile
if not self.test:
zf = zipfile.ZipFile(str(zipfilename), 'w')
# look at all the url's in the project, copy files, remove parts, etc.
# as necessary
extraDirName = None
if extradir:
extraDirName = newproject.name
fix_drive_re = re.compile(r'^(?:file:\/\/\/)?(?:(\w):)?(.*)$')
flist = set()
for source in newproject._urlmap:
part = newproject._urlmap[source]
# gather files from live folders
if part.live and hasattr(part, 'refreshChildren'):
if newproject.live or part._parent.live: continue
flist = flist.union(self._gatherLiveFileUrls(part, newproject._relativeBasedir, extraDirName))
continue
if 'url' in part._tmpAttributes and \
part._tmpAttributes['url'] == part._attributes['url']:
dest = part._tmpAttributes['relativeurl']
else:
dest = uriparse.RelativizeURL(newproject._relativeBasedir, part._attributes['url'])
diskfile = uriparse.URIToLocalPath(part._attributes['url'])
# XXX FIXME this is *VERY HACKY*. I've done a quick fix, but what the !?
# we should never get a full path in dest, it should be relative
if dest.find('file:')==0:
try:
dest = fix_drive_re.sub(r'\1\2',dest)
except Exception, e:
dest = fix_drive_re.sub(r'\2',dest)
# we do not add directories
if os.path.isfile(diskfile):
part._attributes['url'] = dest
if extraDirName:
dest = os.path.join(extraDirName, dest)
if self.debug:
print "diskfile [%r] dest[%r]" % (diskfile, dest)
flist.add((diskfile, dest))
if orig_project:
koProjectFile = orig_project.getFile()
projectDirName = koProjectFile.dirName
if koProjectFile.isLocal:
# For each file in
# .../.komodotools/D/f
# write out fullpath => .komodotools/D/f
ktools = koToolbox2.PROJECT_TARGET_DIRECTORY
toolboxPath = os.path.join(projectDirName, ktools)
if os.path.exists(toolboxPath):
self._archiveDir(zf, projectDirName, toolboxPath)
#.........这里部分代码省略.........