Explorar el Código

Merge pull request #9 from Deuchnord/clear-cache

Add --clear-cache option
tags/v0.2.0
Jérôme Deuchnord hace 4 años
committed by GitHub
padre
commit
bdba65211e
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 2 ficheros con 34 adiciones y 2 borrados
  1. +26
    -1
      kosmorro
  2. +8
    -1
      kosmorrolib/core.py

+ 26
- 1
kosmorro Ver fichero

@@ -17,14 +17,21 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.


import argparse import argparse
import sys
from datetime import date from datetime import date

from kosmorrolib import dumper from kosmorrolib import dumper
from kosmorrolib import core
from kosmorrolib.ephemerides import EphemeridesComputer, Position from kosmorrolib.ephemerides import EphemeridesComputer, Position




def main(): def main():
output_formats = get_dumpers() output_formats = get_dumpers()
args = get_args(list(output_formats.keys())) args = get_args(list(output_formats.keys()))

if args.special_action is not None:
return 0 if args.special_action() else 1

year = args.year year = args.year
month = args.month month = args.month
day = args.day day = args.day
@@ -38,6 +45,8 @@ def main():
dump = output_formats[args.format](ephemerides) dump = output_formats[args.format](ephemerides)
print(dump.to_string()) print(dump.to_string())


return 0



def get_dumpers() -> {str: dumper.Dumper}: def get_dumpers() -> {str: dumper.Dumper}:
return { return {
@@ -46,6 +55,20 @@ def get_dumpers() -> {str: dumper.Dumper}:
} }




def clear_cache() -> bool:
confirm = input("Do you really want to clear Kosmorro's cache? [yN] ").upper()
if confirm == 'Y':
try:
core.clear_cache()
except FileNotFoundError:
pass
elif confirm not in ('N', ''):
print('Answer did not match expected options, cache not cleared.')
return False

return True


def get_args(output_formats: [str]): def get_args(output_formats: [str]):
today = date.today() today = date.today()


@@ -55,6 +78,8 @@ def get_args(output_formats: [str]):
' observer positioned at coordinates (0,0), with an altitude of 0.' ' observer positioned at coordinates (0,0), with an altitude of 0.'
% today.strftime('%a %b %d, %Y')) % today.strftime('%a %b %d, %Y'))


parser.add_argument('--clear-cache', dest='special_action', action='store_const', const=clear_cache, default=None,
help='Delete all the files Kosmorro stored in the cache.')
parser.add_argument('--format', '-f', type=str, default=output_formats[0], choices=output_formats, parser.add_argument('--format', '-f', type=str, default=output_formats[0], choices=output_formats,
help='The format under which the information have to be output') help='The format under which the information have to be output')
parser.add_argument('--latitude', '-lat', type=float, default=0., parser.add_argument('--latitude', '-lat', type=float, default=0.,
@@ -77,4 +102,4 @@ def get_args(output_formats: [str]):




if __name__ == '__main__': if __name__ == '__main__':
main()
sys.exit(main())

+ 8
- 1
kosmorrolib/core.py Ver fichero

@@ -16,11 +16,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.


from shutil import rmtree
from pathlib import Path
from skyfield.api import Loader from skyfield.api import Loader


from .data import Star, Planet, Satellite from .data import Star, Planet, Satellite


VERSION = '0.1.1' VERSION = '0.1.1'
CACHE_FOLDER = str(Path.home()) + '/.kosmorro-cache'


MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']


@@ -37,7 +40,7 @@ ASTERS = [Star('Sun', 'SUN'),




def get_loader(): def get_loader():
return Loader('~/.kosmorro-cache')
return Loader(CACHE_FOLDER)




def get_timescale(): def get_timescale():
@@ -46,3 +49,7 @@ def get_timescale():


def get_skf_objects(): def get_skf_objects():
return get_loader()('de421.bsp') return get_loader()('de421.bsp')


def clear_cache():
rmtree(CACHE_FOLDER)

Cargando…
Cancelar
Guardar