Commit f10b4075 authored by Thorsten Alteholz's avatar Thorsten Alteholz
Browse files

first round of pylint fixes

parent 8b367822
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -41,4 +41,3 @@ __status__ = "Development" # "Prototype", "Development", or "Production"

from types import ModuleType
import sys
+3 −3
Original line number Diff line number Diff line
@@ -26,9 +26,10 @@ ____________________________
#from types import ModuleType
#import sys

import pysqm.main as main
#import pysqm.main as main
from pysqm import main

while(1==1):
while 1==1:
    # Loop forever to make sure the program does not die.
    try:
        main.loop()
@@ -39,4 +40,3 @@ while(1==1):
        print(e)
        print('Trying to restart')
        print('')
+17 −15
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ ____________________________
'''

import math
import ephem
import datetime
import ephem

# Read the config variables from config.py
import pysqm.settings as settings
@@ -37,26 +37,28 @@ def define_ephem_observatory():
    OBS.lat = config._observatory_latitude*ephem.pi/180
    OBS.lon = config._observatory_longitude*ephem.pi/180
    OBS.elev = config._observatory_altitude
    return(OBS)
    return OBS

def remove_linebreaks(data):
    '''remove linebreaks from data'''
    # Remove line breaks from data
    data = data.replace('\r\n','')
    data = data.replace('\r','')
    data = data.replace('\n','')
    return(data)
    return data

def format_value(data,remove_str=' '):
    '''format data'''
    # Remove string and spaces from data
    data = remove_linebreaks(data)
    data = data.replace(remove_str,'')
    data = data.replace(' ','')
    return(data)
    return data

def format_value_list(data,remove_str=' '):
    # Remove string and spaces from data array/list
    data = [format_value(line,remove_str).split(';') for line in data]
    return(data)
    return data

def set_decimals(number,dec=3):
        str_number = str(number)
@@ -64,37 +66,37 @@ def set_decimals(number,dec=3):
        while len(dec_)<=dec:
            dec_=dec_+'0'

        return(int_+'.'+dec_[:dec])
        return int_+'.'+dec_[:dec]

class observatory(object):
    def read_datetime(self):
        # Get UTC datetime from the computer.
        '''Get UTC datetime from the computer.'''
        utc_dt = datetime.datetime.utcnow()
        #utc_dt = datetime.datetime.now() - datetime.timedelta(hours=config._computer_timezone)
                #time.localtime(); daylight_saving=_.tm_isdst>0
        return(utc_dt)
        return utc_dt

    def local_datetime(self,utc_dt):
        # Get Local datetime from the computer, without daylight saving.
        return(utc_dt + datetime.timedelta(hours=config._local_timezone))
        '''Get Local datetime from the computer, without daylight saving.'''
        return utc_dt + datetime.timedelta(hours=config._local_timezone)

    def calculate_sun_altitude(self,OBS,timeutc):
        # Calculate Sun altitude
        '''Calculate Sun altitude'''
        OBS.date = ephem.date(timeutc)
        Sun = ephem.Sun(OBS)
        return(Sun.alt)
        return Sun.alt

    def next_sunset(self,OBS):
        # Next sunset calculation
        '''Next sunset calculation'''
        previous_horizon = OBS.horizon
        OBS.horizon = str(config._observatory_horizon)
        next_setting = OBS.next_setting(ephem.Sun()).datetime()
        next_setting = next_setting.strftime("%Y-%m-%d %H:%M:%S")
        OBS.horizon = previous_horizon
        return(next_setting)
        return next_setting

    def is_nighttime(self,OBS):
        # Is nightime (sun below a given altitude)
        '''Is nightime (sun below a given altitude)'''
        timeutc = self.read_datetime()
        if self.calculate_sun_altitude(OBS,timeutc)*180./math.pi>config._observatory_horizon:
            return False
+10 −2
Original line number Diff line number Diff line
@@ -23,28 +23,35 @@ along with PySQM. If not, see <http://www.gnu.org/licenses/>.
____________________________
'''

import os,sys
import os
import sys


class ArgParser:
    '''parse arguments of program'''

    def __init__(self,inputfile=False):
        self.parse_arguments(inputfile)

    def parse_arguments(self,inputfile):
        '''"do all the parsing work'''
        import argparse
        # Return config filename
        self.parser = argparse.ArgumentParser()
        self.parser.add_argument('-c', '--config', default="config.py")
        if (inputfile):
        if inputfile:
            self.parser.add_argument('-i', '--input', default=None)
        args = self.parser.parse_args()
        vars(self).update(args.__dict__)

    def print_help(self):
        '''print help defined by argparse'''
        self.parser.print_help()


class ConfigFile:
    '''read config file'''

    def __init__(self, path="config.py"):
        # Guess the selected dir and config filename
        # Should accept:
@@ -57,6 +64,7 @@ class ConfigFile:
        self.config = None

    def read_config_file(self,path):
        '''do all the work for reading the config file'''
        # Get the absolute path
        abspath = os.path.abspath(path)
        # Is a dir? Then add config.py (default filename)
+1 −1
Original line number Diff line number Diff line
@@ -23,5 +23,5 @@ setup(name='pysqm',
                   "Operating System :: OS Independent",
                   "Topic :: Scientific/Engineering :: Astronomy",
                   ],
      long_description=open('README.txt').read()
      long_description=open('README.txt', encoding="utf-8").read()
      )