Append `package_uid` to `resource.for_packages`, if the attribute exists and `package_uid` is not already in `resource.for_packages`.
(package_uid, resource, codebase)
| 1005 | |
| 1006 | |
| 1007 | def add_to_package(package_uid, resource, codebase): |
| 1008 | """ |
| 1009 | Append `package_uid` to `resource.for_packages`, if the attribute exists and |
| 1010 | `package_uid` is not already in `resource.for_packages`. |
| 1011 | """ |
| 1012 | if ( |
| 1013 | hasattr(resource, 'for_packages') |
| 1014 | and isinstance(resource.for_packages, list) |
| 1015 | and package_uid |
| 1016 | ): |
| 1017 | if package_uid in resource.for_packages: |
| 1018 | return |
| 1019 | resource.for_packages.append(package_uid) |
| 1020 | resource.save(codebase) |
| 1021 | |
| 1022 | |
| 1023 | class DatafileHandler: |