You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. import os
  5. from odoo import api, models
  6. class ExternalSystemOs(models.Model):
  7. """This is an Interface implementing the OS module.
  8. For the most part, this is just a sample of how to implement an external
  9. system interface. This is still a fully usable implementation, however.
  10. """
  11. _name = 'external.system.os'
  12. _inherit = 'external.system.adapter'
  13. _description = 'External System OS'
  14. previous_dir = None
  15. @api.multi
  16. def external_get_client(self):
  17. """Return a usable client representing the remote system."""
  18. super(ExternalSystemOs, self).external_get_client()
  19. if self.system_id.remote_path:
  20. self.previous_dir = os.getcwd()
  21. os.chdir(self.system_id.remote_path)
  22. return os
  23. @api.multi
  24. def external_destroy_client(self, client):
  25. """Perform any logic necessary to destroy the client connection.
  26. Args:
  27. client (mixed): The client that was returned by
  28. ``external_get_client``.
  29. """
  30. super(ExternalSystemOs, self).external_destroy_client(client)
  31. if self.previous_dir:
  32. os.chdir(self.previous_dir)
  33. self.previous_dir = None