FileManager Class.
| 486 | |
| 487 | |
| 488 | class Filemanager(): |
| 489 | """FileManager Class.""" |
| 490 | |
| 491 | # Stores list of dict for filename & its encoding |
| 492 | loaded_file_encoding_list = [] |
| 493 | |
| 494 | ERROR_NOT_ALLOWED = { |
| 495 | 'Error': gettext('Not allowed'), |
| 496 | 'Code': 0 |
| 497 | } |
| 498 | |
| 499 | def __init__(self, trans_id, ss=''): |
| 500 | self.trans_id = trans_id |
| 501 | self.dir = get_storage_directory() |
| 502 | self.shared_dir = get_storage_directory(shared_storage=ss) |
| 503 | |
| 504 | if self.dir is not None and isinstance(self.dir, list): |
| 505 | self.dir = "" |
| 506 | |
| 507 | @staticmethod |
| 508 | def get_closest_parent(storage_dir, last_dir): |
| 509 | """ |
| 510 | Check if path exists and if not then get closest parent which exists |
| 511 | :param storage_dir: Base dir |
| 512 | :param last_dir: check dir |
| 513 | :return: exist dir |
| 514 | """ |
| 515 | if len(last_dir) > 1 and \ |
| 516 | (last_dir.endswith('/') or last_dir.endswith('\\')): |
| 517 | last_dir = last_dir[:-1] |
| 518 | while last_dir: |
| 519 | if os.path.exists(storage_dir or '' + last_dir): |
| 520 | break |
| 521 | index = max(last_dir.rfind('\\'), last_dir.rfind('/')) \ |
| 522 | if _platform == 'win32' else last_dir.rfind('/') |
| 523 | last_dir = last_dir[0:index] |
| 524 | |
| 525 | if _platform == 'win32': |
| 526 | if not last_dir.endswith('\\'): |
| 527 | last_dir += "\\" |
| 528 | |
| 529 | return last_dir |
| 530 | |
| 531 | if not last_dir.endswith('/'): |
| 532 | last_dir += "/" |
| 533 | |
| 534 | return last_dir |
| 535 | |
| 536 | @staticmethod |
| 537 | def check_capability_permission(capability): |
| 538 | """ |
| 539 | Check if the user has permission for the capability |
| 540 | """ |
| 541 | if capability == 'create': |
| 542 | return current_user.has_permission( |
| 543 | AllPermissionTypes.storage_add_folder) |
| 544 | elif capability == 'delete': |
| 545 | return current_user.has_permission( |
no test coverage detected