Exemplo n.º 1
0
def add_journal(journal_name, xml_config):
    """
    Add a new journal to the DB. Also create the configuration file

    Parameters:
         journal_name  -  the name (used in URLs) of the new journal
           xml_config  -  the xml configuration of the journal (string)
    Returns:
         the id of the journal if successfully added
         -1 if could not be added because journal name already exists
         -2 if config could not be saved
         -3 if could not be added for other reasons
         -4 if database cache could not be added
    """
    try:
        get_journal_id(journal_name)
    except InvenioWebJournalJournalIdNotFoundDBError:
        # Perfect, journal does not exist
        res = run_sql("INSERT INTO jrnJOURNAL (name) VALUES(%s)", (journal_name,))
        # Also save xml_config
        config_dir = '%s/webjournal/%s/' % (CFG_ETCDIR, journal_name)
        try:
            if not os.path.exists(config_dir):
                os.makedirs(config_dir)
            xml_config_file = file(config_dir + journal_name + '-config.xml', 'w')
            xml_config_file.write(xml_config)
            xml_config_file.close()
        except Exception:
            res = -2
        # And save some info in file in case database is down
        journal_info_path = get_journal_info_path(journal_name)
        journal_info_dir = os.path.dirname(journal_info_path)
        if not os.path.exists(journal_info_dir):
            try:
                os.makedirs(journal_info_dir)
            except Exception:
                if res <= 0:
                    res = -4
        journal_info_file = open(journal_info_path, 'w')

        cPickle.dump({'journal_id': res,
                      'journal_name': journal_name,
                      'current_issue':'01/2000'}, journal_info_file)
        return res
    return -1
Exemplo n.º 2
0
def add_journal(journal_name, xml_config):
    """
    Add a new journal to the DB. Also create the configuration file

    Parameters:
         journal_name  -  the name (used in URLs) of the new journal
           xml_config  -  the xml configuration of the journal (string)
    Returns:
         the id of the journal if successfully added
         -1 if could not be added because journal name already exists
         -2 if config could not be saved
         -3 if could not be added for other reasons
         -4 if database cache could not be added
    """
    try:
        get_journal_id(journal_name)
    except InvenioWebJournalJournalIdNotFoundDBError:
        # Perfect, journal does not exist
        res = run_sql("INSERT INTO jrnJOURNAL (name) VALUES(%s)", (journal_name,))
        # Also save xml_config
        config_dir = '%s/webjournal/%s/' % (CFG_ETCDIR, journal_name)
        try:
            if not os.path.exists(config_dir):
                os.makedirs(config_dir)
            xml_config_file = file(config_dir + journal_name + '-config.xml', 'w')
            xml_config_file.write(xml_config)
            xml_config_file.close()
        except Exception:
            res = -2
        # And save some info in file in case database is down
        journal_info_path = get_journal_info_path(journal_name)
        journal_info_dir = os.path.dirname(journal_info_path)
        if not os.path.exists(journal_info_dir):
            try:
                os.makedirs(journal_info_dir)
            except Exception:
                if res <= 0:
                    res = -4
        journal_info_file = open(journal_info_path, 'w')

        cPickle.dump({'journal_id': res,
                      'journal_name': journal_name,
                      'current_issue':'01/2000'}, journal_info_file)
        return res
    return -1
Exemplo n.º 3
0
def release_journal_update(update_issue, journal_name, ln=CFG_SITE_LANG):
    """
    Releases an update to a journal.
    """
    move_drafts_articles_to_ready(journal_name, update_issue)
    journal_id = get_journal_id(journal_name, ln)
    run_sql("UPDATE jrnISSUE set date_released=NOW() \
                WHERE issue_number=%s \
                AND id_jrnJOURNAL=%s", (update_issue,
                                        journal_id))
Exemplo n.º 4
0
def release_journal_update(update_issue, journal_name, ln=CFG_SITE_LANG):
    """
    Releases an update to a journal.
    """
    move_drafts_articles_to_ready(journal_name, update_issue)
    journal_id = get_journal_id(journal_name, ln)
    run_sql("UPDATE jrnISSUE set date_released=NOW() \
                WHERE issue_number=%s \
                AND id_jrnJOURNAL=%s", (update_issue,
                                        journal_id))
Exemplo n.º 5
0
def delete_journal_issue(issue, journal_name, ln=CFG_SITE_LANG):
    """
    Deletes an issue from the DB.
    (Not currently used)
    """
    journal_id = get_journal_id(journal_name, ln)
    run_sql("DELETE FROM jrnISSUE WHERE issue_number=%s \
            AND id_jrnJOURNAL=%s",(issue, journal_id))

    # update information in file (in case DB is down)
    journal_info_path = get_journal_info_path(journal_name)
    journal_info_file = open(journal_info_path, 'w')
    cPickle.dump({'journal_id': journal_id,
                  'journal_name': journal_name,
                  'current_issue': get_current_issue(ln, journal_name)},
                 journal_info_file)
Exemplo n.º 6
0
def delete_journal_issue(issue, journal_name, ln=CFG_SITE_LANG):
    """
    Deletes an issue from the DB.
    (Not currently used)
    """
    journal_id = get_journal_id(journal_name, ln)
    run_sql("DELETE FROM jrnISSUE WHERE issue_number=%s \
            AND id_jrnJOURNAL=%s",(issue, journal_id))

    # update information in file (in case DB is down)
    journal_info_path = get_journal_info_path(journal_name)
    journal_info_file = open(journal_info_path, 'w')
    cPickle.dump({'journal_id': journal_id,
                  'journal_name': journal_name,
                  'current_issue': get_current_issue(ln, journal_name)},
                 journal_info_file)
Exemplo n.º 7
0
def update_DB_for_alert(issue, journal_name, ln):
    """
    Update the 'last sent alert' timestamp for the given journal and
    issue.

    Parameters:
         journal_name  -  the journal for which we want to update the time
                          of last alert
                issue  -  the issue for which we want to update the time
                          of last alert
                   ln  -  language
    """
    journal_id = get_journal_id(journal_name, ln)
    run_sql("UPDATE jrnISSUE set date_announced=NOW() \
                WHERE issue_number=%s \
                AND id_jrnJOURNAL=%s", (issue,
                                        journal_id))
Exemplo n.º 8
0
def update_DB_for_alert(issue, journal_name, ln):
    """
    Update the 'last sent alert' timestamp for the given journal and
    issue.

    Parameters:
         journal_name  -  the journal for which we want to update the time
                          of last alert
                issue  -  the issue for which we want to update the time
                          of last alert
                   ln  -  language
    """
    journal_id = get_journal_id(journal_name, ln)
    run_sql("UPDATE jrnISSUE set date_announced=NOW() \
                WHERE issue_number=%s \
                AND id_jrnJOURNAL=%s", (issue,
                                        journal_id))
Exemplo n.º 9
0
def was_alert_sent_for_issue(issue, journal_name, ln):
    """
    Returns False if alert has not already been sent for given journal and
    issue, else returns time of last alert, as time tuple

    Parameters:
         journal_name  -  the journal for which we want to check last alert
                issue  -  the issue for which we want to check last alert
                   ln  -  language
    Returns:
         time tuple or False. Eg: (2008, 4, 25, 7, 58, 37, 4, 116, -1)
    """
    journal_id = get_journal_id(journal_name, ln)
    date_announced = run_sql("SELECT date_announced FROM jrnISSUE \
                                WHERE issue_number=%s \
                                AND id_jrnJOURNAL=%s", (issue, journal_id))[0][0]
    if date_announced == None:
        return False
    else:
        return date_announced.timetuple()
Exemplo n.º 10
0
def was_alert_sent_for_issue(issue, journal_name, ln):
    """
    Returns False if alert has not already been sent for given journal and
    issue, else returns time of last alert, as time tuple

    Parameters:
         journal_name  -  the journal for which we want to check last alert
                issue  -  the issue for which we want to check last alert
                   ln  -  language
    Returns:
         time tuple or False. Eg: (2008, 4, 25, 7, 58, 37, 4, 116, -1)
    """
    journal_id = get_journal_id(journal_name, ln)
    date_announced = run_sql("SELECT date_announced FROM jrnISSUE \
                                WHERE issue_number=%s \
                                AND id_jrnJOURNAL=%s", (issue, journal_id))[0][0]
    if date_announced == None:
        return False
    else:
        return date_announced.timetuple()
Exemplo n.º 11
0
def release_journal_issue(publish_issues, journal_name, ln=CFG_SITE_LANG):
    """
    Releases a new issue.

    This sets the current issue in the database to 'publish_issues' for
    given 'journal_name'

    Parameters:
         journal_name  -  the journal for which we release a new issue
       publish_issues  -  the list of issues that will be considered as
                          current (there can be several)
                   ln  -  language
    """
    journal_id = get_journal_id(journal_name, ln)
    if len(publish_issues) > 1:
        publish_issues.sort(compare_issues)
        low_bound = publish_issues[0]
        high_bound = publish_issues[-1]
        issue_display = '%s-%s/%s' % (low_bound.split("/")[0],
                                      high_bound.split("/")[0],
                                      high_bound.split("/")[1])
        # remember convention: if we are going over a new year, take the higher
    else:
        issue_display = publish_issues[0]
    # produce the DB lines
    for publish_issue in publish_issues:
        move_drafts_articles_to_ready(journal_name, publish_issue)
        run_sql("INSERT INTO jrnISSUE (id_jrnJOURNAL, issue_number, issue_display) \
                VALUES(%s, %s, %s)", (journal_id,
                                      publish_issue,
                                      issue_display))
    # set first issue to published
    release_journal_update(publish_issues[0], journal_name, ln)

    # update information in file (in case DB is down)
    journal_info_path = get_journal_info_path(journal_name)
    journal_info_file = open(journal_info_path, 'w')
    cPickle.dump({'journal_id': journal_id,
                  'journal_name': journal_name,
                  'current_issue': get_current_issue(ln, journal_name)},
                 journal_info_file)
Exemplo n.º 12
0
def release_journal_issue(publish_issues, journal_name, ln=CFG_SITE_LANG):
    """
    Releases a new issue.

    This sets the current issue in the database to 'publish_issues' for
    given 'journal_name'

    Parameters:
         journal_name  -  the journal for which we release a new issue
       publish_issues  -  the list of issues that will be considered as
                          current (there can be several)
                   ln  -  language
    """
    journal_id = get_journal_id(journal_name, ln)
    if len(publish_issues) > 1:
        publish_issues.sort(compare_issues)
        low_bound = publish_issues[0]
        high_bound = publish_issues[-1]
        issue_display = '%s-%s/%s' % (low_bound.split("/")[0],
                                      high_bound.split("/")[0],
                                      high_bound.split("/")[1])
        # remember convention: if we are going over a new year, take the higher
    else:
        issue_display = publish_issues[0]
    # produce the DB lines
    for publish_issue in publish_issues:
        move_drafts_articles_to_ready(journal_name, publish_issue)
        run_sql("INSERT INTO jrnISSUE (id_jrnJOURNAL, issue_number, issue_display) \
                VALUES(%s, %s, %s)", (journal_id,
                                      publish_issue,
                                      issue_display))
    # set first issue to published
    release_journal_update(publish_issues[0], journal_name, ln)

    # update information in file (in case DB is down)
    journal_info_path = get_journal_info_path(journal_name)
    journal_info_file = open(journal_info_path, 'w')
    cPickle.dump({'journal_id': journal_id,
                  'journal_name': journal_name,
                  'current_issue': get_current_issue(ln, journal_name)},
                 journal_info_file)