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.

69 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
  5. # @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from .abstract_fs import AbstractFSTask
  22. from base64 import b64decode
  23. from fs import osfs
  24. import logging
  25. _logger = logging.getLogger(__name__)
  26. class FileStoreTask(AbstractFSTask):
  27. _key = 'filestore'
  28. _name = 'File Store'
  29. _synchronize_type = None
  30. _default_port = None
  31. _hide_login = True
  32. _hide_password = True
  33. _hide_port = True
  34. class FileStoreImportTask(FileStoreTask):
  35. _synchronize_type = 'import'
  36. def run(self):
  37. att_ids = []
  38. with osfs.OSFS(self.host) as fs_conn:
  39. files_to_process = self._get_files(fs_conn, self.path)
  40. for file_to_process in files_to_process:
  41. att_ids.append(self._process_file(fs_conn, file_to_process))
  42. return att_ids
  43. class FileStoreExportTask(FileStoreTask):
  44. _synchronize_type = 'export'
  45. def run(self, async=True):
  46. for attachment in self.attachment_ids:
  47. if attachment.state in ('pending', 'failed'):
  48. self.attachment_id = attachment
  49. with osfs.OSFS(self.host) as fs_conn:
  50. self._upload_file(fs_conn,
  51. self.host,
  52. self.port,
  53. self.user,
  54. self.pwd,
  55. self.path,
  56. attachment.datas_fname,
  57. b64decode(attachment.datas))