Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.handle_moves(submenu)
# parse move operations
for move in menu.Moves:
move_from_menu = menu.getMenu(move.Old)
if move_from_menu:
# FIXME: this is assigned, but never used...
move_to_menu = menu.getMenu(move.New)
menus = move.New.split("/")
oldparent = None
while len(menus) > 0:
if not oldparent:
oldparent = menu
newmenu = oldparent.getMenu(menus[0])
if not newmenu:
newmenu = Menu()
newmenu.Name = menus[0]
if len(menus) > 1:
newmenu.NotInXml = True
oldparent.addSubmenu(newmenu)
oldparent = newmenu
menus.pop(0)
newmenu += move_from_menu
move_from_menu.parent.Submenus.remove(move_from_menu)
def _populateFromEntry(self, node, parent=None, progress=None):
# for some reason xdg hiddes some entries, but we don't like that
for entry in node.getEntries(hidden=True):
self._dbg(2, "entry: %s" % (entry))
if isinstance(entry, xdg.Menu.Menu):
# we found a toplevel menu
name = xmlescape(entry.getName())
self._dbg(1, "we have a sub-menu %s " % name)
item = Category(self, name, entry.getIcon())
#print "adding: %s" % name
self.pickle[item] = []
self._populateFromEntry(entry, item, progress=progress)
elif isinstance(entry, xdg.Menu.MenuEntry):
# more debug output
#self._dbg(3, node.getPath() + "/\t" + entry.DesktopFileID + "\t" + entry.DesktopEntry.getFileName())
# we found a application
name = xmlescape(entry.DesktopEntry.getName())
#self._dbg(1, "we have a application %s (%s) " % (name,entry.DesktopFileID))
if name and entry.DesktopEntry.hasKey("X-AppInstall-Package"):
self._dbg(2,"parent is %s" % parent.name)
def merge_legacy_dir(self, dir_, prefix, filename, parent):
dir_ = _check_file_path(dir_, filename, TYPE_DIR)
if dir_ and dir_ not in self._directory_dirs:
self._directory_dirs.add(dir_)
m = Menu()
m.AppDirs.append(dir_)
m.DirectoryDirs.append(dir_)
m.Name = os.path.basename(dir_)
m.NotInXml = True
for item in os.listdir(dir_):
try:
if item == ".directory":
m.Directories.append(item)
elif os.path.isdir(os.path.join(dir_, item)):
m.addSubmenu(self.merge_legacy_dir(
os.path.join(dir_, item),
prefix,
filename,
parent
))
def createMenu(self, parent, name, genericname=None, comment=None, icon=None, after=None, before=None):
menu = Menu()
menu.Parent = parent
menu.Depth = parent.Depth + 1
menu.Layout = parent.DefaultLayout
menu.DefaultLayout = parent.DefaultLayout
menu = self.editMenu(menu, name, genericname, comment, icon)
self.__addEntry(parent, menu, after, before)
self.menu.sort()
return menu
def get_menu(menu):
for entry in menu.getEntries():
if isinstance(entry, xdg.Menu.Menu):
get_menu(entry)
elif isinstance(entry, xdg.Menu.MenuEntry):
desktops[entry.DesktopEntry.getFileName()] = {
'name': entry.DesktopEntry.getName(),
'desktop': entry.DesktopEntry.getFileName()
}
if menuentry.DesktopFileID not in _entries:
self.Entries.append(menuentry)
elif order[1] == "menus" or order[1] == "all":
self.Submenus.sort()
for submenu in self.Submenus:
if submenu.Name not in _submenus:
if submenu.Layout.inline:
self.merge_inline(submenu)
else:
self.Entries.append(submenu)
# getHidden / NoDisplay / OnlyShowIn / NotOnlyShowIn / Deleted / NoExec
for entry in self.Entries:
entry.Show = True
self.Visible += 1
if isinstance(entry, Menu):
if entry.Deleted is True:
entry.Show = "Deleted"
self.Visible -= 1
elif isinstance(entry.Directory, MenuEntry):
if entry.Directory.DesktopEntry.getNoDisplay():
entry.Show = "NoDisplay"
self.Visible -= 1
elif entry.Directory.DesktopEntry.getHidden():
entry.Show = "Hidden"
self.Visible -= 1
elif isinstance(entry, MenuEntry):
if entry.DesktopEntry.getNoDisplay():
entry.Show = "NoDisplay"
self.Visible -= 1
elif entry.DesktopEntry.getHidden():
entry.Show = "Hidden"
if after or before:
if after:
index = parent.Entries.index(after) + 1
elif before:
index = parent.Entries.index(before)
parent.Entries.insert(index, entry)
else:
parent.Entries.append(entry)
xml_parent = self.__getXmlMenu(parent.getPath(True, True))
if isinstance(entry, MenuEntry):
parent.MenuEntries.append(entry)
entry.Parents.append(parent)
self.__addXmlFilename(xml_parent, entry.DesktopFileID, "Include")
elif isinstance(entry, Menu):
parent.addSubmenu(entry)
if after or before:
self.__addLayout(parent)
self.__addXmlLayout(xml_parent, parent.Layout)
def parse_menu(self, node, filename):
menu = Menu()
self.parse_node(node, filename, menu)
return menu