| 226 | """ |
| 227 | |
| 228 | def run(self): |
| 229 | if ( |
| 230 | not os.path.exists(SALT_VERSION_HARDCODED) |
| 231 | or self.distribution.with_salt_version |
| 232 | ): |
| 233 | # Write the version file |
| 234 | if getattr(self.distribution, "salt_version_hardcoded_path", None) is None: |
| 235 | self.distribution.salt_version_hardcoded_path = SALT_VERSION_HARDCODED |
| 236 | sys.stderr.write("This command is not meant to be called on it's own\n") |
| 237 | sys.stderr.flush() |
| 238 | |
| 239 | if not self.distribution.with_salt_version: |
| 240 | salt_version = SALT_VERSION |
| 241 | else: |
| 242 | from salt.version import SaltStackVersion |
| 243 | |
| 244 | salt_version = SaltStackVersion.parse( |
| 245 | self.distribution.with_salt_version |
| 246 | ) |
| 247 | if os.path.exists(self.distribution.salt_version_hardcoded_path): |
| 248 | log.warn( |
| 249 | "The 'salt/_version.txt' file already exists. Not overwriting it." |
| 250 | ) |
| 251 | return |
| 252 | |
| 253 | with open( |
| 254 | self.distribution.salt_version_hardcoded_path, "w", encoding="utf-8" |
| 255 | ) as wfh: |
| 256 | wfh.write(str(salt_version)) |
| 257 | |
| 258 | |
| 259 | class GenerateSaltSyspaths(Command): |