FaradayRF / Faraday-Software

Faraday node software
https://www.faradayrf.com
Other
47 stars 19 forks source link

Application Configuration File Logic With Package Installation Methods #239

Open kb1lqc opened 7 years ago

kb1lqc commented 7 years ago

Summary

Weird name I know... Basically I noticed that after pip install faraday that if I was in the github main repo folder performing Faraday configuration commands such as faraday-proxy --init-config and faraday-proxy --callsign... the local /etc/faraday files are edited instead of the main installation files. While not a bug that stops operation it could be annoying when you don't realize that running faraday from a different folder location might result in using different configuration files!

@kb1lqd @reillyeon @el-iso

Problem Explanation

I would expect with a pip install in non-editable mode to see (Windows) C:\Python27\etc\faraday file change. The local etc/faraday files are really only for editable pip installs. The following steps need to be taken

Environment

Software

Master Branch

Hardware

Faraday Rev D1

Supporting Information

N/A

kb1lqc commented 6 years ago

As a note I learned about os.path.expanduser("~") with aprs2influxdb work... probably useful here.

def getConfig():
        """Open configuration file and return a list of config database

        Searches the current directory as well as Python specific install
        location such as /etc/<installPath> or C:/python27/<installPath>.
        Returns a list of config file desciptor as well as the path it was found
        at so other operations can use it to open the file.
        """
        # Known paths where loggingConfig.ini can exist
        installPath = os.path.join(sys.prefix, "etc", "aprs2influxdb", "config.ini")
        installPath2 = os.path.join(os.path.expanduser("~"), ".local", "etc", "aprs2influxdb", "config.ini")
        localPath = os.path.join(os.curdir, "config.ini")

        # Check all directories until first instance of loggingConfig.ini
        for location in localPath, installPath, installPath2:
            try:
                config = ConfigParser.RawConfigParser()
                result = config.read(location)
            except ConfigParser.NoSectionError:
                pass

            if result:
                break

        return [config, location]