"""
Copyright 2018-2020 VMware, Inc.  All rights reserved. -- VMware Confidential

Dummy vmware-horizon-integrated-printing component.
"""

DEST = LIBDIR/'vmware/view/integratedPrinting'

class VMwareHorizonIntegratedPrinting(Installer):
   def InitializeQuestions(self, old, new, upgrade):
      defaultVMIP = self.GetAnswer('vmipEnable')
      if defaultVMIP:
         qlevel = 'CUSTOM'
      else:
         qlevel = 'REGULAR'

      self.AddMultiChoiceQuestion(
         'YesNo',
         key='vmipEnable',
         text='VMware Integrated Printing',
         required=True,
         default='yes',
         footer='The VMware Integrated Printing component allows you to use '
                'local or network printers from a remote desktop without '
                'requiring that additional print drivers be installed in '
                'the remote desktop.',
         level=qlevel)

   def InitializeInstall(self, old, new, upgrade):
      vmipEnable = self.GetAnswer('vmipEnable')
      if vmipEnable == 'yes':
          self.AddTarget(
             'File',
             'lib/vmware/view/vdpService/libvmwprvdpplugin.so',
             LIBDIR/'vmware/view/vdpService/libvmwprvdpplugin.so')
          self.SetPermission(
             LIBDIR/'vmware/view/vdpService/libvmwprvdpplugin.so', BINARY)
          self.AddTarget('File', 'lib/vmware/view/integratedPrinting/*', DEST)
          self.SetPermission(DEST/'*', BINARY)

      if (CONFDIR/'abortInstall').exists():
         raise InstallError('View abort install')

   def InitializeUninstall(self, old, new, upgrade):
      if (CONFDIR/'abortUninstall').exists():
         raise InstallError('View aborting uninstall')
      self.RunCommand('true', ignoreErrors=True)

   def PreUninstall(self, old, new, upgrade):
      vmipEnable = self.GetAnswer('vmipEnable')
      if vmipEnable == 'yes':
         self.RunCommand(
            '/bin/bash',
            DEST/'integrated-printing-setup.sh',
            '-u',
            ignoreErrors=True)

   def PostInstall(self, old, new, upgrade):
      self.SetConfig('vmipComponent', 'test')
      vmipEnable = self.GetAnswer('vmipEnable')
      if vmipEnable == 'yes':
         self.RunCommand(
            '/bin/bash', DEST/'integrated-printing-setup.sh', '-i',
            ignoreErrors=True)
         self.AddScanFile(LIBDIR/'vmware/view/vdpService/libvmwprvdpplugin.so')
         self.AddScanFile(
            LIBDIR/'vmware/view/integratedPrinting/vmware-print-redir-client')
         self.AddScanFile(
            LIBDIR/'vmware/view/integratedPrinting/prlinuxcupsppd')

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