"""
Copyright 2017 VMware, Inc.  All rights reserved. -- VMware Confidentia

vmware-horizon-media-provider component.
"""

import platform
class VMwareHorizonMultiMediaProvider(Installer):
   def InitializeQuestions(self, old, new, upgrade):
      defaultMediaProvider = self.GetAnswer('mediaproviderEnable')
      if defaultMediaProvider:
         qlevel = 'CUSTOM'
      else:
         qlevel = 'REGULAR'

      self.AddMultiChoiceQuestion('YesNo',
                                  key='mediaproviderEnable',
                                  text='VMware Horizon(R) Virtualization Pack for Skype for Business',
                                  required=True,
                                  default='yes',
                                  footer='VMware Horizon(R) Virtualization Pack for Skype for Business enables Skype for business on linux view client.',
                                  level=qlevel)

   def InitializeInstall(self, old, new, upgrade):
      mediaproviderEnable = self.GetAnswer('mediaproviderEnable')
      if mediaproviderEnable == 'yes':
         self.AddTarget('File', 'etc/*', SYSCONFDIR/'udev/rules.d/')
         self.AddTarget('File', 'lib/*', LIBDIR/'vmware/mediaprovider/')
         self.SetPermission(LIBDIR/'vmware/mediaprovider/libVMWMediaProvider.so', BINARY)

      if (CONFDIR/'abortInstall').exists():
         raise InstallError('VMware Horizon(R) Virtualization Pack for Skype for Business aborting install')

   def InitializeUninstall(self, old, new, upgrade):
      if (CONFDIR/'abortUninstall').exists():
         raise InstallError('VMware Horizon(R) Virtualization Pack for Skype for Business aborting uninstall')
      self.RunCommand('true', ignoreErrors=True)

   def PostInstall(self, old, new, upgrade):
      self.SetConfig('mediaproviderComponent', 'test')
      mediaproviderEnable = self.GetAnswer('mediaproviderEnable')
      if mediaproviderEnable == 'yes':
         self.AddScanFile(LIBDIR/'vmware/mediaprovider/libVMWMediaProvider.so')

   def PostUninstall(self, old, new, upgrade):
      self.DelConfig('mediaproviderComponent')
      self.DelConfig('mediaproviderComponent')
