本文整理汇总了Python中xpcom.server.UnwrapObject.getProjectForURL方法的典型用法代码示例。如果您正苦于以下问题:Python UnwrapObject.getProjectForURL方法的具体用法?Python UnwrapObject.getProjectForURL怎么用?Python UnwrapObject.getProjectForURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xpcom.server.UnwrapObject
的用法示例。
在下文中一共展示了UnwrapObject.getProjectForURL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KoToolbox2ToolManager
# 需要导入模块: from xpcom.server import UnwrapObject [as 别名]
# 或者: from xpcom.server.UnwrapObject import getProjectForURL [as 别名]
#.........这里部分代码省略.........
return self._getFullyRealizedToolById(ids)
return self.getToolById(res[0])
def getToolsWithKeyboardShortcuts(self, dbPath):
ids = self.toolbox_db.getIDsForToolsWithKeyboardShortcuts(dbPath)
return self._getFullyRealizedToolById(ids)
def getTriggerMacros(self, dbPath):
ids = self.toolbox_db.getTriggerMacroIDs(dbPath)
return self._getFullyRealizedToolById(ids)
def _getFullyRealizedToolById(self, ids):
# We load tools lazily, so make sure these have the keyboard
# shortcuts and other info in them.
tools = []
for id in ids:
tool = self.getToolById(id)
if tool:
# Trigger macros need to be fully initialized,
# since they can be invoked
tool.updateSelf()
tools.append(tool)
return tools
def _renameObject(self, id, newName, isContainer):
tool = self.getToolById(id)
parentTool = tool.get_parent()
if parentTool is None:
raise ServerException(nsError.NS_ERROR_ILLEGAL_VALUE,
"Can't rename a top-level folder")
oldPath = tool.path
if isContainer:
newPathOnDisk = self._prepareUniqueFileSystemName(tool, parentTool.path, newName, ext="")
else:
newPathOnDisk = self._prepareUniqueFileSystemName(tool, parentTool.path,
newName)
os.rename(oldPath, newPathOnDisk)
# Update the name field in the json tool
try:
fp = open(newPathOnDisk, 'r')
data = koToolbox2.DataParser.readData(fp)
fp.close()
if data['name'] != newName:
# If these are the same, we're doing a null rename, but
# treat that as an anomaly.
pass
data['name'] = newName;
fp = open(newPathOnDisk, 'r+')
koToolbox2.DataParser.writeData(fp, data)
fp.close()
except:
log.exception("Failed to update json on old path:%s, newName:%s",
newPathOnDisk, newName)
# There shouldn't be an exception in the database.
self.toolbox_db.renameTool(id, newName, newPathOnDisk)
try:
# Remove this item from the cache, since its name changed.
del self._tools[id]
except KeyError:
pass
if isContainer:
# Update the paths of all child nodes.
ids = self.toolbox_db.updateChildPaths(id, oldPath, newPathOnDisk)
for id in ids:
try:
# Remove this item from the cache, since its name changed.
del self._tools[id]
except KeyError:
pass
return newPathOnDisk
def renameContainer(self, id, newName):
self._renameObject(id, newName, isContainer=True)
def renameItem(self, id, newName):
self._renameObject(id, newName, isContainer=False)
def removeChangedCachedTool(self, id):
try:
del self._tools[id]
except:
pass
def getToolRoot(self, id):
return self.toolbox_db.getRootId(id)
# Commands: get the prefset for a command by getting it either
# from the current project, if that's who owns the tool,
# or use the global prefs.
def get_prefset(self, toolId):
rootId = self.getToolRoot(toolId)
projectURL = self._koToolbox2Service.getProjectURL(rootId)
if projectURL is not None:
proj = self._koProjectService.getProjectForURL(projectURL)
if proj is not None:
return proj.prefset
return self._globalPrefs