def get_set_last_update(set_spec=""): """ Returns the last_update of a given set (or of all sets) in UTC """ if set_spec: last_update = run_sql("SELECT " + datetime_format('MAX(last_updated)') + """ FROM "oaiREPOSITORY" WHERE setSpec=%s""", (set_spec, ))[0][0] else: last_update = run_sql("SELECT " + datetime_format('MAX(last_updated)', False) + """ FROM "oaiREPOSITORY" """)[0][0] if last_update: return localtime_to_utc(last_update) else: return None
def get_job_result(job_result_id): """Loads job result from the database. @param job_result_id: identifier of the job result @return: JobResult object containing information about the job result or None if job result with this identifier does not exist""" if not _exist_job_result(job_result_id): return None query = """SELECT id, "id_expJOB", """ + \ datetime_format('execution_time') + ',' + \ """ status, status_message FROM "expJOBRESULT" WHERE id=%s""" query_result = run_sql(query, (job_result_id, )) (id, job_id, execution_date_time, status, status_message) = query_result[0] job = get_job(job_id) query_results = _get_query_results_for_job_result(id) job_result = JobResult(job, query_results, convert_datetext_to_datestruct(execution_date_time), id, status, status_message) return job_result
def get_job_by_name(job_name): """Loads the first job with the given name found in database. @param job_name: name of the job @return: Job object containf information about the job or None if the job does not exist""" query = """SELECT id, jobname, jobfreq, output_format, """ + \ datetime_format('lastrun') + ',' + \ """ output_directory FROM "expJOB" WHERE jobname=%s""" query_result = run_sql(query, (job_name,)) if 0 == len(query_result): return None (id, name, frequency, output_format, last_run, output_directory) = query_result[0] job = Job(id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) return job
def get_job_result(job_result_id): """Loads job result from the database. @param job_result_id: identifier of the job result @return: JobResult object containing information about the job result or None if job result with this identifier does not exist""" if not _exist_job_result(job_result_id): return None query = """SELECT id, "id_expJOB", """ + \ datetime_format('execution_time') + ',' + \ """ status, status_message FROM "expJOBRESULT" WHERE id=%s""" query_result = run_sql(query, (job_result_id,)) (id, job_id, execution_date_time, status, status_message) = query_result[0] job = get_job(job_id) query_results = _get_query_results_for_job_result(id) job_result = JobResult(job, query_results, convert_datetext_to_datestruct(execution_date_time), id, status, status_message) return job_result
def get_job(job_id): """Loads job from the database. @param job_id: identifier of the job @return: Job object containf information about the job or None if the job does not exist""" if not _exist_job(job_id): return None query = """SELECT id, jobname, jobfreq, output_format, """ + \ datetime_format('lastrun') + ',' + \ """ output_directory FROM "expJOB" WHERE id=%s""" query_result = run_sql(query, (job_id,)) (id, name, frequency, output_format, last_run, output_directory) = query_result[0] job = Job(id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) return job
def get_job_by_name(job_name): """Loads the first job with the given name found in database. @param job_name: name of the job @return: Job object containf information about the job or None if the job does not exist""" query = """SELECT id, jobname, jobfreq, output_format, """ + \ datetime_format('lastrun') + ',' + \ """ output_directory FROM "expJOB" WHERE jobname=%s""" query_result = run_sql(query, (job_name, )) if 0 == len(query_result): return None (id, name, frequency, output_format, last_run, output_directory) = query_result[0] job = Job(id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) return job
def get_set_last_update(set_spec=""): """ Returns the last_update of a given set (or of all sets) in UTC """ if set_spec: last_update = run_sql( "SELECT " + datetime_format('MAX(last_updated)') + """ FROM "oaiREPOSITORY" WHERE setSpec=%s""", (set_spec, ))[0][0] else: last_update = run_sql("SELECT " + datetime_format('MAX(last_updated)', False) + """ FROM "oaiREPOSITORY" """)[0][0] if last_update: return localtime_to_utc(last_update) else: return None
def get_all_jobs(user_id): """Loads all jobs from the database. @param user_id: identifier of the user owning the jobs @return: list of Job objects containing all the jobs owned by the user given as a parameter""" query = """SELECT "expJOB".id, "expJOB".jobname, "expJOB".jobfreq, "expJOB".output_format, """ + \ datetime_format('"expJOB".lastrun') + ',' + \ """ "expJOB".output_directory FROM "expJOB" INNER JOIN "user_expJOB" ON "expJOB".id = "user_expJOB"."id_expJOB" WHERE "user_expJOB".id_user = %s AND "expJOB".deleted = 0 """ query_parameters = (user_id, ) query_result = run_sql(query, query_parameters) all_jobs = [] for (job_id, name, frequency, output_format, last_run, output_directory) in query_result: job = Job(job_id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) all_jobs.append(job) return all_jobs
def get_all_messages_for_user(uid): """ Get all messages for a user's inbox, without the eventual non-expired reminders. @param uid: user id @return: [(message_id, id_user_from, nickname_user_from, message_subject, message_sent_date, message_status)] """ update_user_inbox_for_reminders(uid) reminder_status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER'] return run_sql("""SELECT m.id, m.id_user_from, u.nickname, m.subject, """ + datetime_format('m.sent_date') + ', ' + """ um.status FROM user_msgMESSAGE um, msgMESSAGE m, user u WHERE um.id_user_to = %s AND !(BINARY um.status=%s) AND um.id_msgMESSAGE=m.id AND u.id=m.id_user_from ORDER BY m.sent_date DESC """, (uid, reminder_status))
def get_all_messages_for_user(uid): """ Get all messages for a user's inbox, without the eventual non-expired reminders. @param uid: user id @return: [(message_id, id_user_from, nickname_user_from, message_subject, message_sent_date, message_status)] """ update_user_inbox_for_reminders(uid) reminder_status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER'] return run_sql("""SELECT m.id, m.id_user_from, u.nickname, m.subject, """ + \ datetime_format('m.sent_date') + ', ' + \ """ um.status FROM user_msgMESSAGE um, msgMESSAGE m, user u WHERE um.id_user_to = %s AND !(BINARY um.status=%s) AND um.id_msgMESSAGE=m.id AND u.id=m.id_user_from ORDER BY m.sent_date DESC """, (uid, reminder_status))
def get_job(job_id): """Loads job from the database. @param job_id: identifier of the job @return: Job object containf information about the job or None if the job does not exist""" if not _exist_job(job_id): return None query = """SELECT id, jobname, jobfreq, output_format, """ + \ datetime_format('lastrun') + ',' + \ """ output_directory FROM "expJOB" WHERE id=%s""" query_result = run_sql(query, (job_id, )) (id, name, frequency, output_format, last_run, output_directory) = query_result[0] job = Job(id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) return job
def get_message(uid, msgid): """ get a message with its status @param uid: user id @param msgid: message id @return: a (message_id, id_user_from, nickname_user_from, sent_to_user_nicks, sent_to_group_names, subject, body, sent_date, received_date, status) formed tuple or 0 (ZERO) if none found """ query = ( """SELECT m.id, m.id_user_from, u.nickname, m.sent_to_user_nicks, m.sent_to_group_names, m.subject, m.body, """ + datetime_format("m.sent_date") + ", " + datetime_format("m.received_date") + ", " + """ um.status FROM msgMESSAGE m, user_msgMESSAGE um, user u WHERE m.id=%s AND um.id_msgMESSAGE=%s AND um.id_user_to=%s AND u.id=m.id_user_from""" ) params = (msgid, msgid, uid) res = run_sql(query, params) if res: return res[0] else: return 0
def get_earliest_datestamp(): """Get earliest datestamp in the database Return empty string if no records or earliest datestamp in UTC. """ out = CFG_MIN_DATE res = run_sql("SELECT " + datetime_format('MIN(creation_date)', False) + " FROM bibrec", n=1) if res and res[0][0]: out = localtime_to_utc(res[0][0]) return out
def get_latest_datestamp(): """Get latest datestamp in the database Return empty string if no records or latest datestamp in UTC. """ out = CFG_MAX_DATE res = run_sql("SELECT " + datetime_format("MAX(modification_date)", False) + " FROM bibrec", n=1) if res and res[0][0]: out = localtime_to_utc(res[0][0]) return out
def get_modification_date(recid): """Returns the date of last modification for the record 'recid'. Return empty string if no record or modification date in UTC. """ out = "" res = run_sql("SELECT " + datetime_format("modification_date") + " FROM bibrec WHERE id=%s", (recid,), 1) if res and res[0][0]: out = localtime_to_utc(res[0][0]) return out
def get_message(uid, msgid): """ get a message with its status @param uid: user id @param msgid: message id @return: a (message_id, id_user_from, nickname_user_from, sent_to_user_nicks, sent_to_group_names, subject, body, sent_date, received_date, status) formed tuple or 0 (ZERO) if none found """ query = """SELECT m.id, m.id_user_from, u.nickname, m.sent_to_user_nicks, m.sent_to_group_names, m.subject, m.body, """ + \ datetime_format('m.sent_date') + ', ' + \ datetime_format('m.received_date') + ', ' + \ """ um.status FROM msgMESSAGE m, user_msgMESSAGE um, user u WHERE m.id=%s AND um.id_msgMESSAGE=%s AND um.id_user_to=%s AND u.id=m.id_user_from""" params = (msgid, msgid, uid) res = run_sql(query, params) if res: return res[0] else: return 0
def get_modification_date(recid): """Returns the date of last modification for the record 'recid'. Return empty string if no record or modification date in UTC. """ out = "" res = run_sql( "SELECT " + datetime_format('modification_date') + " FROM bibrec WHERE id=%s", (recid, ), 1) if res and res[0][0]: out = localtime_to_utc(res[0][0]) return out
def get_earliest_datestamp(): """Get earliest datestamp in the database Return empty string if no records or earliest datestamp in UTC. """ out = CFG_MIN_DATE res = run_sql("SELECT " + datetime_format('MIN(creation_date)', False) + " FROM bibrec", n=1) if res and res[0][0]: out = localtime_to_utc(res[0][0]) return out
def get_rnk(rnkID=''): """Return one or all rank methods rnkID - return the rank method given, or all if not given""" try: if rnkID: res = run_sql( """SELECT id,name, """ + \ datetime_format('last_updated') + \ """ from "rnkMETHOD" WHERE id=%s""" % rnkID) else: res = run_sql( """SELECT id,name, """ + \ datetime_format('last_updated') + \ """ from "rnkMETHOD" """) return res except StandardError as e: return ()
def get_all_jobs(user_id): """Loads all jobs from the database. @param user_id: identifier of the user owning the jobs @return: list of Job objects containing all the jobs owned by the user given as a parameter""" query = """SELECT "expJOB".id, "expJOB".jobname, "expJOB".jobfreq, "expJOB".output_format, """ + \ datetime_format('"expJOB".lastrun') + ',' + \ """ "expJOB".output_directory FROM "expJOB" INNER JOIN "user_expJOB" ON "expJOB".id = "user_expJOB"."id_expJOB" WHERE "user_expJOB".id_user = %s AND "expJOB".deleted = 0 """ query_parameters = (user_id, ) query_result = run_sql(query, query_parameters) all_jobs = [] for (job_id, name, frequency, output_format, last_run, output_directory) in query_result: job = Job(job_id, name, frequency, output_format, convert_datetext_to_datestruct(last_run), output_directory) all_jobs.append(job) return all_jobs