Ejemplo n.º 1
0
"""
Delete a galaxy and all it's related data.
"""
import argparse
import logging
from archive.delete_galaxy_mod import delete_galaxy
from config import DB_LOGIN
from sqlalchemy import create_engine

LOG = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)-15s:' + logging.BASIC_FORMAT)

parser = argparse.ArgumentParser('Delete Galaxy by galaxy_id')
parser.add_argument('galaxy_id', nargs='+', help='the galaxy_id or 4-30 if you need a range')
args = vars(parser.parse_args())

galaxy_ids = None
if len(args['galaxy_id']) == 1 and args['galaxy_id'][0].find('-') > 1:
    list_range = args['galaxy_id'][0].split('-')
    LOG.info('Range from %s to %s', list[0], list[1])
    galaxy_ids = range(int(list_range[0]), int(list_range[1]) + 1)
else:
    galaxy_ids = args['galaxy_id']

# First check the galaxy exists in the database
ENGINE = create_engine(DB_LOGIN)
connection = ENGINE.connect()

delete_galaxy(connection, galaxy_ids)
connection.close()
Ejemplo n.º 2
0
from sqlalchemy import create_engine, and_
from sqlalchemy.sql import select
from database.database_support_core import GALAXY

LOG = config_logger(__name__)
LOG.info('PYTHONPATH = {0}'.format(sys.path))

# Get the arguments
parser = argparse.ArgumentParser('Delete Galaxies that have been stored')
parser.add_argument('-mod', '--mod', nargs=2, help=' M N - the modulus M to used and which value to check N ')
args = vars(parser.parse_args())

# First check the galaxy exists in the database
ENGINE = create_engine(DB_LOGIN)
connection = ENGINE.connect()

delete_delay_ago = datetime.datetime.now() - datetime.timedelta(days=float(ARC_DELETE_DELAY))
LOG.info('Deleting {0} days ago ({1})'.format(ARC_DELETE_DELAY, delete_delay_ago))
if args['mod'] is None:
    select_statement = select([GALAXY]).where(and_(GALAXY.c.status_id == STORED, GALAXY.c.status_time < delete_delay_ago)).order_by(GALAXY.c.galaxy_id)
else:
    select_statement = select([GALAXY]).where(and_(GALAXY.c.status_id == STORED, GALAXY.c.status_time < delete_delay_ago, GALAXY.c.galaxy_id % args['mod'][0] == args['mod'][1])).order_by(GALAXY.c.galaxy_id)
    LOG.info('Using modulus {0} - remainder {1}'.format(args['mod'][0], args['mod'][1]))

galaxy_ids = []
for galaxy in connection.execute(select_statement):
    galaxy_ids.append(galaxy[GALAXY.c.galaxy_id])

delete_galaxy(connection, galaxy_ids[0:20])
connection.close()
Ejemplo n.º 3
0
    help=' M N - the modulus M to used and which value to check N ')
args = vars(parser.parse_args())

# First check the galaxy exists in the database
ENGINE = create_engine(DB_LOGIN)
connection = ENGINE.connect()

delete_delay_ago = datetime.datetime.now() - datetime.timedelta(
    days=float(ARC_DELETE_DELAY))
LOG.info('Deleting {0} days ago ({1})'.format(ARC_DELETE_DELAY,
                                              delete_delay_ago))
if args['mod'] is None:
    select_statement = select([GALAXY]).where(
        and_(GALAXY.c.status_id == STORED,
             GALAXY.c.status_time < delete_delay_ago)).order_by(
                 GALAXY.c.galaxy_id)
else:
    select_statement = select([GALAXY]).where(
        and_(GALAXY.c.status_id == STORED,
             GALAXY.c.status_time < delete_delay_ago, GALAXY.c.galaxy_id %
             args['mod'][0] == args['mod'][1])).order_by(GALAXY.c.galaxy_id)
    LOG.info('Using modulus {0} - remainder {1}'.format(
        args['mod'][0], args['mod'][1]))

galaxy_ids = []
for galaxy in connection.execute(select_statement):
    galaxy_ids.append(galaxy[GALAXY.c.galaxy_id])

delete_galaxy(connection, galaxy_ids[0:20])
connection.close()
Ejemplo n.º 4
0
import argparse
import logging
from archive.delete_galaxy_mod import delete_galaxy
from config import DB_LOGIN
from sqlalchemy import create_engine

LOG = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)-15s:' + logging.BASIC_FORMAT)

parser = argparse.ArgumentParser('Delete Galaxy by galaxy_id')
parser.add_argument('galaxy_id',
                    nargs='+',
                    help='the galaxy_id or 4-30 if you need a range')
args = vars(parser.parse_args())

galaxy_ids = None
if len(args['galaxy_id']) == 1 and args['galaxy_id'][0].find('-') > 1:
    list_range = args['galaxy_id'][0].split('-')
    LOG.info('Range from %s to %s', list[0], list[1])
    galaxy_ids = range(int(list_range[0]), int(list_range[1]) + 1)
else:
    galaxy_ids = args['galaxy_id']

# First check the galaxy exists in the database
ENGINE = create_engine(DB_LOGIN)
connection = ENGINE.connect()

delete_galaxy(connection, galaxy_ids)
connection.close()