mik-laj commented on a change in pull request #8290: Add airflow info command URL: https://github.com/apache/airflow/pull/8290#discussion_r407951101
########## 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()) Review comment: I wanted this function to return only constants that are defined. Other results are erroneous and we should improve the function so that it returns correct values rather than random values from the code's point of view. It is worth adding that the detailed information you are asking for is already displayed on the screen. ``` Platform: [Mac OS, x86_64] uname_result(system='Darwin', node='Kamils-MacBook-Pro.local', release='19.4.0', version='Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64', machine='x86_64', processor='i386') ``` ``` Platform: [Linux, x86_64] uname_result(system='Linux', node='eeefbb427a9c', release='4.19.76-linuxkit', version='#1 SMP Thu Oct 17 19:31:58 UTC 2019', machine='x86_64', processor='') ``` ---------------------------------------------------------------- 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
