turbaszek commented on a change in pull request #8290: Add airflow info command URL: https://github.com/apache/airflow/pull/8290#discussion_r407942261
########## File path: airflow/cli/commands/info_command.py ########## @@ -0,0 +1,318 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Config sub-commands""" +import getpass +import locale +import os +import platform +import subprocess +import sys +import textwrap +from typing import Optional + +from typing_extensions import Protocol + +from airflow import configuration +from airflow.version import version as airflow_version + + +class Anonymizer(Protocol): + """Anonymizer protocol.""" + + def process_path(self, value): + """Remove pii from paths""" + + +class NullAnonymizer(Anonymizer): + """Do nothing.""" + + def process_path(self, value): + return value + + +class PiiAnonymizer(Anonymizer): + """Remove personally identifiable info from path.""" + + def __init__(self): + home_path = os.path.expanduser("~") + username = getpass.getuser() + self._path_replacements = {home_path: "${HOME}", username: "${USER}"} + + def process_path(self, value): + if not value: + return value + for src, target in self._path_replacements.items(): + value = value.replace(src, target) + return value + + +class OperatingSystem: + """Operating system""" + + WINDOWS = "Windows" + LINUX = "Linux" + MACOSX = "Mac OS" + CYGWIN = "Cygwin" + + @staticmethod + def get_current() -> Optional[str]: + """Get current operating system""" + if os.name == "nt": + return OperatingSystem.WINDOWS + elif "linux" in sys.platform: + return OperatingSystem.LINUX + elif "darwin" in sys.platform: + return OperatingSystem.MACOSX + elif "cygwin" in sys.platform: + return OperatingSystem.CYGWIN + return None + + +class Architecture: + """Compute architecture""" + + X86_64 = "x86_64" + X86 = "x86" + PPC = "ppc" + ARM = "arm" + + @staticmethod + def get_current(): + """Get architecture""" + return _MACHINE_TO_ARCHITECTURE.get(platform.machine().lower()) + + +_MACHINE_TO_ARCHITECTURE = { + "amd64": Architecture.X86_64, + "x86_64": Architecture.X86_64, + "i686-64": Architecture.X86_64, + "i386": Architecture.X86, + "i686": Architecture.X86, + "x86": Architecture.X86, + "ia64": Architecture.X86, # Itanium is different x64 arch, treat it as the common x86. + "powerpc": Architecture.PPC, + "power macintosh": Architecture.PPC, + "ppc64": Architecture.PPC, + "armv6": Architecture.ARM, + "armv6l": Architecture.ARM, + "arm64": Architecture.ARM, + "armv7": Architecture.ARM, + "armv7l": Architecture.ARM, +} Review comment: @mik-laj have you checked if there's already a nice package to collect such information? Or at least should consider using https://docs.python.org/3/library/platform.html ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
