Yield Detection objects detected in the file at ``location``. The flags ``include_copyrights``, ``include_holders`` and ``include_authors`` drive which actual detections are done and returned. For copyrights only: - If ``include_copyright_years`` is True, include years and yea
(
location,
include_copyrights=True,
include_holders=True,
include_authors=True,
include_copyright_years=True,
include_copyright_allrights=False,
deadline=sys.maxsize,
)
| 86 | |
| 87 | |
| 88 | def detect_copyrights( |
| 89 | location, |
| 90 | include_copyrights=True, |
| 91 | include_holders=True, |
| 92 | include_authors=True, |
| 93 | include_copyright_years=True, |
| 94 | include_copyright_allrights=False, |
| 95 | deadline=sys.maxsize, |
| 96 | ): |
| 97 | """ |
| 98 | Yield Detection objects detected in the file at ``location``. |
| 99 | |
| 100 | The flags ``include_copyrights``, ``include_holders`` and |
| 101 | ``include_authors`` drive which actual detections are done and returned. |
| 102 | |
| 103 | For copyrights only: |
| 104 | - If ``include_copyright_years`` is True, include years and year ranges. |
| 105 | - If ``include_copyright_allrights`` is True, include trailing |
| 106 | "all rights reserved"-style mentions |
| 107 | |
| 108 | Strip markup from text if ``demarkup`` is True. |
| 109 | Run for up to ``deadline`` seconds and return results found so far. |
| 110 | """ |
| 111 | from cluecode.linux_credits import detect_credits_authors |
| 112 | |
| 113 | from textcode.analysis import numbered_text_lines |
| 114 | |
| 115 | if include_authors: |
| 116 | author_detections = list(detect_credits_authors(location)) |
| 117 | |
| 118 | if TRACE: |
| 119 | logger_debug('detect_copyrights: detect_credits_authors') |
| 120 | for detecta in author_detections: |
| 121 | logger_debug(f' {detecta}') |
| 122 | |
| 123 | # bail out if we have a credits file with credits |
| 124 | if author_detections: |
| 125 | for a in author_detections: |
| 126 | yield a |
| 127 | return |
| 128 | |
| 129 | numbered_lines = list(numbered_text_lines(location, demarkup=True)) |
| 130 | |
| 131 | if TRACE or TRACE_TOK: |
| 132 | logger_debug('detect_copyrights: numbered_lines') |
| 133 | for nl in numbered_lines: |
| 134 | logger_debug(' numbered_line:', repr(nl)) |
| 135 | |
| 136 | include_copyright_years = include_copyrights and include_copyright_years |
| 137 | include_copyright_allrights = include_copyrights and include_copyright_allrights |
| 138 | |
| 139 | yield from detect_copyrights_from_lines( |
| 140 | numbered_lines=numbered_lines, |
| 141 | include_copyrights=include_copyrights, |
| 142 | include_holders=include_holders, |
| 143 | include_authors=include_authors, |
| 144 | include_copyright_years=include_copyright_years, |
| 145 | include_copyright_allrights=include_copyright_allrights, |