Make appmenu paths properties and not config attrs

This fixes a circular dependencies where get_attrs_config() in QubesVm is
executed, before the self.storage is initialised. See also
https://github.com/QubesOS/qubes-core-admin/pull/6#discussion-diff-45008401
This commit is contained in:
Bahtiar `kalkin-` Gadimov 2015-11-22 12:25:10 +01:00
parent 4d94309087
commit 6590931fcd

View File

@ -17,9 +17,8 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# # USA.
#
import subprocess import subprocess
import sys import sys
@ -48,39 +47,41 @@ system_path['appmenu_remove_cmd'] = \
'/usr/libexec/qubes-appmenus/remove-appvm-appmenus.sh' '/usr/libexec/qubes-appmenus/remove-appvm-appmenus.sh'
def QubesVm_get_attrs_config(self, attrs): def QubesVm_get_appmenus_templates_dir(self):
attrs["appmenus_templates_dir"] = { if self.updateable:
"func": lambda x: return self.absolute_path(vm_files["appmenus_templates_subdir"], None)
self.absolute_path(vm_files["appmenus_templates_subdir"], None) elif self.template is not None:
if self.updateable else return self.template.appmenus_templates_dir
(self.template.appmenus_templates_dir if self.template is not None else:
else None) return None
}
attrs["appmenus_template_icons_dir"] = { QubesVm.appmenus_templates_dir = property(QubesVm_get_appmenus_templates_dir)
"func": lambda x:
self.absolute_path(vm_files["appmenus_template_icons_subdir"], None)
if self.updateable else
(self.template.appmenus_template_icons_dir
if self.template is not None else None)
}
attrs["appmenus_dir"] = {
"func": lambda x:
self.absolute_path(vm_files["appmenus_subdir"], None)}
attrs["appmenus_icons_dir"] = {
"func": lambda x:
self.absolute_path(vm_files["appmenus_icons_subdir"], None)}
return attrs
def QubesTemplateVm_get_attrs_config(self, attrs): def QubesVm_get_appmenus_template_icons_dir(self):
attrs['appmenus_templates_dir'] = { if self.updateable:
'func': lambda x: return self.absolute_path(vm_files["appmenus_template_icons_subdir"],
os.path.join(self.dir_path, vm_files["appmenus_templates_subdir"])} None)
attrs['appmenus_template_icons_dir'] = { elif self.template:
'func': lambda x: return self.template.appmenus_template_icons_dir
os.path.join(self.dir_path, else:
vm_files["appmenus_template_icons_subdir"])} return None
return attrs
QubesVm.appmenus_template_icons_dir = \
property(QubesVm_get_appmenus_template_icons_dir)
def QubesVm_get_appmenus_dir(self):
return self.absolute_path(vm_files["appmenus_subdir"], None)
QubesVm.appmenus_dir = property(QubesVm_get_appmenus_dir)
def QubesVm_get_appmenus_icons_dir(self):
return self.absolute_path(vm_files["appmenus_icons_subdir"], None)
QubesVm.appmenus_icons_dir = property(QubesVm_get_appmenus_icons_dir)
def QubesVm_appmenus_create(self, verbose=False, source_template=None): def QubesVm_appmenus_create(self, verbose=False, source_template=None):
@ -132,6 +133,7 @@ def QubesVm_appmenus_remove(self):
subprocess.check_call([system_path["appmenu_remove_cmd"], self.name, subprocess.check_call([system_path["appmenu_remove_cmd"], self.name,
vmtype], stderr=open(os.devnull, 'w')) vmtype], stderr=open(os.devnull, 'w'))
def QubesVm_appmenus_cleanup(self): def QubesVm_appmenus_cleanup(self):
srcdir = self.appmenus_templates_dir srcdir = self.appmenus_templates_dir
if srcdir is None: if srcdir is None:
@ -145,6 +147,7 @@ def QubesVm_appmenus_cleanup(self):
if not os.path.exists(os.path.join(srcdir, appmenu)): if not os.path.exists(os.path.join(srcdir, appmenu)):
os.unlink(os.path.join(self.appmenus_dir, appmenu)) os.unlink(os.path.join(self.appmenus_dir, appmenu))
def QubesVm_appicons_create(self, srcdir=None): def QubesVm_appicons_create(self, srcdir=None):
if srcdir is None: if srcdir is None:
srcdir = self.appmenus_template_icons_dir srcdir = self.appmenus_template_icons_dir
@ -357,6 +360,7 @@ def QubesVm_set_attr(self, name, newvalue, oldvalue):
elif not newvalue and oldvalue: elif not newvalue and oldvalue:
self.appmenus_create() self.appmenus_create()
# new methods # new methods
QubesVm.appmenus_create = QubesVm_appmenus_create QubesVm.appmenus_create = QubesVm_appmenus_create
QubesVm.appmenus_remove = QubesVm_appmenus_remove QubesVm.appmenus_remove = QubesVm_appmenus_remove
@ -368,7 +372,6 @@ QubesVm.appicons_cleanup = QubesVm_appicons_cleanup
QubesVm.appicons_remove = QubesVm_appicons_remove QubesVm.appicons_remove = QubesVm_appicons_remove
# hooks for existing methods # hooks for existing methods
QubesVm.hooks_get_attrs_config.append(QubesVm_get_attrs_config)
QubesVm.hooks_pre_rename.append(QubesVm_pre_rename) QubesVm.hooks_pre_rename.append(QubesVm_pre_rename)
QubesVm.hooks_post_rename.append(QubesVm_post_rename) QubesVm.hooks_post_rename.append(QubesVm_post_rename)
QubesVm.hooks_create_on_disk.append(QubesVm_create_on_disk) QubesVm.hooks_create_on_disk.append(QubesVm_create_on_disk)