Locates the project for a path.
(cls, path, extension_required=False)
| 55 | |
| 56 | @classmethod |
| 57 | def from_path(cls, path, extension_required=False): |
| 58 | """Locates the project for a path.""" |
| 59 | path = os.path.abspath(path) |
| 60 | if os.path.isfile(path) and ( |
| 61 | not extension_required or path.endswith(".lektorproject") |
| 62 | ): |
| 63 | return cls.from_file(path) |
| 64 | |
| 65 | try: |
| 66 | files = [ |
| 67 | x for x in os.listdir(path) if x.lower().endswith(".lektorproject") |
| 68 | ] |
| 69 | except OSError: |
| 70 | return None |
| 71 | |
| 72 | if len(files) == 1: |
| 73 | return cls.from_file(os.path.join(path, files[0])) |
| 74 | |
| 75 | if os.path.isdir(path) and os.path.isfile( |
| 76 | os.path.join(path, "content/contents.lr") |
| 77 | ): |
| 78 | return cls( |
| 79 | name=os.path.basename(path), |
| 80 | project_file=None, |
| 81 | tree=path, |
| 82 | ) |
| 83 | return None |
| 84 | |
| 85 | @classmethod |
| 86 | def discover(cls, base=None): |