Esempio n. 1
0
def receive_after_delete(mapper, connection, target: SeismicDataModel):
    try:
        file_path = target.file_path
        target.delete_file()
        app_logger.info("File {} was deleted.".format(file_path))

    except FileNotFound:
        app_logger.info("File {} was already deleted.".format(target.filename))
def delete_user(user_id):
    user: UserModel = UserModel.find_by_id(user_id)
    if not user:
        raise UserNotFound("The user id {} doesn't exist".format(user_id))

    deleted = user.delete()
    if deleted:
        app_logger.info("User {} has been deleted".format(user.username))
    else:
        app_logger.warning("User {} could't be deleted.".format(user.username))

    return response.bool_to_response(deleted)
Esempio n. 3
0
def delete_location(loc_id):
    loc: LocationModel = LocationModel.find_by_id(loc_id)
    if not loc:
        raise EntityNotFound("The location id {} doesn't exist".format(loc_id))

    deleted = loc.delete()
    if deleted:
        app_logger.info("Location {} has been deleted at station {}.".format(
            loc.name, loc.station_id))
    else:
        app_logger.warning(
            "Location {} could't be deleted at station {}.".format(
                loc.name, loc.station_id))

    return response.bool_to_response(deleted)
Esempio n. 4
0
def delete_station(station_id):
    station: StationModel = StationModel.find_by_id(station_id)
    if not station:
        raise EntityNotFound(
            "The station id {} doesn't exist".format(station_id))

    deleted = station.delete()
    if deleted:
        app_logger.info("Station {} - {} has been deleted".format(
            station.name, station.creation_date))
    else:
        app_logger.warning("Station {} - {} could't be deleted.".format(
            station.name, station.creation_date))

    return response.bool_to_response(deleted)
Esempio n. 5
0
def delete_attached_file(attached_id):
    attached: StationAttachedFileModel = StationAttachedFileModel.find_by_id(
        attached_id)
    if not attached:
        raise EntityNotFound(
            "The file id {} doesn't exist".format(attached_id))

    deleted = attached.delete()
    if deleted:
        app_logger.info("Attached file {} has been deleted".format(
            attached.filename))
    else:
        app_logger.warning("Channel {} could't be deleted.".format(
            attached.filename))

    return response.bool_to_response(deleted)
Esempio n. 6
0
def delete_channel(channel_id):
    channel: ChannelModel = ChannelModel.find_by_id(channel_id)
    if not channel:
        raise EntityNotFound(
            "The channel id {} doesn't exist".format(channel_id))

    deleted = channel.delete()
    if deleted:
        app_logger.info("Channel {}-{}-{} has been deleted".format(
            channel.get_station().name, channel.name,
            DateUtils.convert_datetime_to_utc(channel.start_time)))
    else:
        app_logger.warning("Channel {}-{}-{} could't be deleted.".format(
            channel.get_station().name, channel.name,
            DateUtils.convert_datetime_to_utc(channel.start_time)))

    return response.bool_to_response(deleted)
Esempio n. 7
0
def login(username=None, password=None):

    user = UserModel.find_by_username(username)

    if user and user.has_valid_password(password):

        # create a token for user.
        token_model = TokenModel.find_by_user_id(user.id)
        if not token_model:
            # create if token don't exist.
            token_model = TokenModel.create_token(user.id)

        if token_model.save():
            app_logger.info("User {} logged in successfully.".format(username))
            return response.model_to_response(user)
        else:
            app_logger.warning("User {} fail to login.".format(username))
            return response.empty_response()

    app_logger.info("User {} has bad credentials.".format(username))
    return response.empty_response()
Esempio n. 8
0
 def __exit__(self, exc_type, exc_value, traceback):
     self.lock.release()
     LOCK_IDS.pop(self.lock_id, None)
     app_logger.info("Unlock {} at: {}".format(self.lock_id, datetime.datetime.now()))
Esempio n. 9
0
 def __enter__(self):
     self.lock.acquire()
     app_logger.info("Lock {} at: {}".format(self.lock_id, datetime.datetime.now()))
     return self