def main():
    """Core loop."""
    logfilename = '%s/fulltext_files_migration_kit-%s.log' % (CFG_LOGDIR, datetime.today().strftime('%Y%m%d%H%M%S'))
    try:
        logfile = open(logfilename, 'w')
    except IOError, e:
        print wrap_text_in_a_box('NOTE: it\'s impossible to create the log:\n\n  %s\n\nbecause of:\n\n  %s\n\nPlease run this migration kit as the same user who runs Invenio (e.g. Apache)' % (logfilename, e), style='conclusion', break_long=False)
        sys.exit(1)
def main():
    """Core loop."""
    logfilename = '%s/fulltext_files_migration_kit-%s.log' % (CFG_LOGDIR, datetime.today().strftime('%Y%m%d%H%M%S'))
    try:
        logfile = open(logfilename, 'w')
    except IOError, e:
        print wrap_text_in_a_box('NOTE: it\'s impossible to create the log:\n\n  %s\n\nbecause of:\n\n  %s\n\nPlease run this migration kit as the same user who runs Invenio (e.g. Apache)' % (logfilename, e), style='conclusion', break_long=False)
        sys.exit(1)
Example #3
0
def migrate_passwords():
    print wrap_text_in_a_box(
        title="Password migration kit (for Invenio prior to v0.92.1)",
        style='conclusion')
    print "Checking your installation..."
    if __check_update_possibility():
        print "Tables are OK."
    else:
        print "No need to update."
        sys.exit(1)
    admin_pwd = __get_admin_pwd()
    print "There are %i passwords to migrate (including guest users)" % __count_current_passwords(
    )
    print "========================================================="
    print "Creating backup...",
    sys.stdout.flush()
    if __creating_backup():
        print "OK"
    else:
        __print_error()
    print "Migrating all Null password to ''...",
    sys.stdout.flush()
    if __migrate_passwords_from_null_to_empty_quotes():
        print "OK"
    else:
        __print_error(True)
    print "Changing the column type from string to blob...",
    sys.stdout.flush()
    if __migrate_column_from_string_to_blob():
        print "OK"
    else:
        __print_error(True)
    print "Encrypting passwords...",
    sys.stdout.flush()
    if __encrypt_password():
        print "OK"
    else:
        __print_error(True)
    print "Checking that admin could enter...",
    sys.stdout.flush()
    if __check_admin(admin_pwd):
        print "OK"
    else:
        __print_error(True)
    print "Removing backup...",
    sys.stdout.flush()
    if __removing_backup():
        print "OK"
    else:
        __print_error()
    print "========================================================="
    print "Migration to encrypted local passwords has been successful."
def main():
    """Core loop."""
    check_running_process_user()
    logfilename = "%s/fulltext_files_migration_kit-%s.log" % (CFG_LOGDIR, datetime.today().strftime("%Y%m%d%H%M%S"))
    try:
        logfile = open(logfilename, "w")
    except IOError, e:
        print wrap_text_in_a_box(
            "NOTE: it's impossible to create the log:\n\n  %s\n\nbecause of:\n\n  %s\n\nPlease run this migration kit as the same user who runs Invenio (e.g. Apache)"
            % (logfilename, e),
            style="conclusion",
            break_long=False,
        )
        sys.exit(1)
def migrate_passwords():
    print wrap_text_in_a_box(title="Password migration kit (for Invenio prior to v0.92.1)", style="conclusion")
    print "Checking your installation..."
    if __check_update_possibility():
        print "Tables are OK."
    else:
        print "No need to update."
        sys.exit(1)
    admin_pwd = __get_admin_pwd()
    print "There are %i passwords to migrate (including guest users)" % __count_current_passwords()
    print "========================================================="
    print "Creating backup...",
    sys.stdout.flush()
    if __creating_backup():
        print "OK"
    else:
        __print_error()
    print "Migrating all Null password to ''...",
    sys.stdout.flush()
    if __migrate_passwords_from_null_to_empty_quotes():
        print "OK"
    else:
        __print_error(True)
    print "Changing the column type from string to blob...",
    sys.stdout.flush()
    if __migrate_column_from_string_to_blob():
        print "OK"
    else:
        __print_error(True)
    print "Encrypting passwords...",
    sys.stdout.flush()
    if __encrypt_password():
        print "OK"
    else:
        __print_error(True)
    print "Checking that admin could enter...",
    sys.stdout.flush()
    if __check_admin(admin_pwd):
        print "OK"
    else:
        __print_error(True)
    print "Removing backup...",
    sys.stdout.flush()
    if __removing_backup():
        print "OK"
    else:
        __print_error()
    print "========================================================="
    print "Migration to encrypted local passwords has been successful."
Example #6
0
    def test_real_longtext_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box long text."""
        text = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."""

        result = """
************************************************************************
** Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do   **
** eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut     **
** enim ad minim veniam, quis nostrud exercitation ullamco laboris    **
** nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in  **
** reprehenderit in voluptate velit esse cillum dolore eu fugiat      **
** nulla pariatur. Excepteur sint occaecat cupidatat non proident,    **
** sunt in culpa qui officia deserunt mollit anim id est laborum.     **
** At vero eos et accusamus et iusto odio dignissimos ducimus qui     **
** blanditiis praesentium voluptatum deleniti atque corrupti quos     **
** dolores et quas molestias excepturi sint occaecati cupiditate non  **
** provident, similique sunt in culpa qui officia deserunt mollitia   **
** animi, id est laborum et dolorum fuga. Et harum quidem rerum       **
** facilis est et expedita distinctio. Nam libero tempore, cum soluta **
** nobis est eligendi optio cumque nihil impedit quo minus id quod    **
** maxime placeat facere possimus, omnis voluptas assumenda est,      **
** omnis dolor repellendus. Temporibus autem quibusdam et aut         **
** officiis debitis aut rerum necessitatibus saepe eveniet ut et      **
** voluptates repudiandae sint et molestiae non recusandae. Itaque    **
** earum rerum hic tenetur a sapiente delectus, ut aut reiciendis     **
** voluptatibus maiores alias consequatur aut perferendis doloribus   **
** asperiores repellat.                                               **
************************************************************************
"""
        self.assertEqual(wrap_text_in_a_box(text), result)
Example #7
0
 def _display_YN_box(self, msg):
     """Utility to display confirmation boxes."""
     msg += ' (Y/N)'
     msg = wrap_text_in_a_box(msg, style='no_border')
     rows = msg.split('\n')
     height = len(rows) + 2
     width = max([len(row) for row in rows]) + 4
     self.win = self.curses.newwin(height, width,
                                   (self.height - height) / 2 + 1,
                                   (self.width - width) / 2 + 1)
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     try:
         while 1:
             c = self.win.getch()
             if c in (ord('y'), ord('Y')):
                 return True
             elif c in (ord('n'), ord('N')):
                 return False
     finally:
         self.panel = None
    def test_real_longtext_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box long text."""
        text = """CDS Invenio (formerly CDSware), the integrated digital library system, is a suite of applications which provides the framework and tools for building and managing an autonomous digital library server. The software is readily available to anyone, as it is free software, licensed under the GNU General Public Licence (GPL). The technology offered by the software covers all aspects of digital library management. It complies with the Open Archives Initiative metadata harvesting protocol (OAI-PMH) and uses MARC 21 as its underlying bibliographic standard. Its flexibility and performance make it a comprehensive solution for the management of document repositories of moderate to large size.

CDS Invenio is developed by, maintained by, and used at, the CERN Document Server. At CERN, CDS Invenio manages over 500 collections of data, consisting of over 800,000 bibliographic records, covering preprints, articles, books, journals, photographs, and more. Besides CERN, CDS Invenio is currently installed and in use by over a dozen scientific institutions worldwide (see the Demo page for details)

If you would like to try it out yourself, please feel free to download our latest version. If you have any questions about the product or our support service, do not hesitate to check out CDS Invenio mailing list archives or to contact us."""

        result = """
************************************************************************
** CDS Invenio (formerly CDSware), the integrated digital library     **
** system, is a suite of applications which provides the framework    **
** and tools for building and managing an autonomous digital library  **
** server. The software is readily available to anyone, as it is free **
** software, licensed under the GNU General Public Licence (GPL). The **
** technology offered by the software covers all aspects of digital   **
** library management. It complies with the Open Archives Initiative  **
** metadata harvesting protocol (OAI-PMH) and uses MARC 21 as its     **
** underlying bibliographic standard. Its flexibility and performance **
** make it a comprehensive solution for the management of document    **
** repositories of moderate to large size.                            **
** CDS Invenio is developed by, maintained by, and used at, the CERN  **
** Document Server. At CERN, CDS Invenio manages over 500 collections **
** of data, consisting of over 800,000 bibliographic records,         **
** covering preprints, articles, books, journals, photographs, and    **
** more. Besides CERN, CDS Invenio is currently installed and in use  **
** by over a dozen scientific institutions worldwide (see the Demo    **
** page for details)                                                  **
** If you would like to try it out yourself, please feel free to      **
** download our latest version. If you have any questions about the   **
** product or our support service, do not hesitate to check out CDS   **
** Invenio mailing list archives or to contact us.                    **
************************************************************************
"""
        self.assertEqual(wrap_text_in_a_box(text), result)
Example #9
0
 def _display_YN_box(self, msg):
     """Utility to display confirmation boxes."""
     msg += ' (Y/N)'
     msg = wrap_text_in_a_box(msg, style='no_border')
     rows = msg.split('\n')
     height = len(rows) + 2
     width = max([len(row) for row in rows]) + 4
     self.win = self.curses.newwin(
         height,
         width,
         (self.height - height) / 2 + 1,
         (self.width - width) / 2 + 1
     )
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     try:
         while 1:
             c = self.win.getch()
             if c in (ord('y'), ord('Y')):
                 return True
             elif c in (ord('n'), ord('N')):
                 return False
     finally:
         self.panel = None
Example #10
0
 def _display_ask_string_box(self, msg, default=""):
     """Utility to display confirmation boxes."""
     msg = wrap_text_in_a_box(msg, style='no_border')
     rows = msg.split('\n')
     height = len(rows) + 3
     width = max([len(row) for row in rows]) + 4
     self.win = self.curses.newwin(
         height,
         width,
         (self.height - height) / 2 + 1,
         (self.width - width) / 2 + 1
     )
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     self.win.move(height - 2, 2)
     self.curses.echo()
     for c in reversed(default):
         self.curses.ungetch(c)
     ret = self.win.getstr()
     self.curses.noecho()
     self.panel = None
     return ret
Example #11
0
    def test_indented_text_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box indented text."""
        text = """
    def test_real_squared_wrap_text_in_a_box(self):\n
        \"""wrap_text_in_a_box - squared style.\"""\n
        result = \"""\n
+--------+\n
| foobar |\n
+--------+
\"""
"""
        result = """
******************************
**     def test_real_square **
**     d_wrap_text_in_a_box **
**     (self):              **
**         \"""wrap_text_in_ **
**         a_box - squared  **
**         style.\"""        **
**         result = \"""     **
** +--------+               **
** | foobar |               **
** +--------+\"""            **
******************************
"""
        self.assertEqual(
            wrap_text_in_a_box(text, min_col=0, max_col=30, break_long=True),
            result)
Example #12
0
def cmd_upgrade(dummy_conf, upgrader=None):
    """ Command for applying upgrades """
    from invenio.config import CFG_LOGDIR
    from invenio.textutils import wrap_text_in_a_box, wait_for_user

    logfilename = os.path.join(CFG_LOGDIR, 'invenio_upgrader.log')
    if not upgrader:
        upgrader = InvenioUpgrader()
    logger = upgrader.get_logger(logfilename=logfilename)

    try:
        upgrades = upgrader.get_upgrades()

        if not upgrades:
            logger.info("All upgrades have been applied.")
            return

        logger.info("Following upgrade(s) will be applied:")

        for u in upgrades:
            title = u['__doc__']
            if title:
                logger.info(" * %s (%s)" % (u['id'], title))
            else:
                logger.info(" * %s" % u['id'])

        logger.info("Running pre-upgrade checks...")
        upgrader.pre_upgrade_checks(upgrades)

        logger.info("Calculating estimated upgrade time...")
        estimate = upgrader.human_estimate(upgrades)

        wait_for_user(
            wrap_text_in_a_box(
                """WARNING: You are going to upgrade your installation (estimated time: %s)!"""
                % estimate))

        for u in upgrades:
            title = u['__doc__']
            if title:
                logger.info("Applying %s (%s)" % (u['id'], title))
            else:
                logger.info("Applying %s" % u['id'])
            upgrader.apply_upgrade(u)

        logger.info("Running post-upgrade checks...")
        upgrader.post_upgrade_checks(upgrades)

        if upgrader.has_warnings():
            logger.warning("Upgrade completed with %s warnings - please check "
                           "log-file for further information:\nless %s" %
                           (upgrader.get_warnings_count(), logfilename))
        else:
            logger.info("Upgrade completed successfully.")
    except RuntimeError, e:
        for msg in e.args:
            logger.error(unicode(msg))
        logger.info("Please check log file for further information:\n"
                    "less %s" % logfilename)
        sys.exit(1)
    def test_indented_text_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box indented text."""
        text = """
    def test_real_squared_wrap_text_in_a_box(self):\n
        \"""wrap_text_in_a_box - squared style.\"""\n
        result = \"""\n
+--------+\n
| foobar |\n
+--------+
\"""
"""
        result = """
******************************
**     def test_real_square **
**     d_wrap_text_in_a_box **
**     (self):              **
**         \"""wrap_text_in_ **
**         a_box - squared  **
**         style.\"""        **
**         result = \"""     **
** +--------+               **
** | foobar |               **
** +--------+\"""            **
******************************
"""
        self.assertEqual(wrap_text_in_a_box(text, min_col=0, max_col=30, break_long=True), result)
Example #14
0
    def test_real_nothing_at_all_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box nothing at all."""
        result = """
******
******
"""
        self.assertEqual(wrap_text_in_a_box(min_col=0), result)
    def test_real_longtext_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box long text."""
        text = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."""

        result = """
************************************************************************
** Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do   **
** eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut     **
** enim ad minim veniam, quis nostrud exercitation ullamco laboris    **
** nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in  **
** reprehenderit in voluptate velit esse cillum dolore eu fugiat      **
** nulla pariatur. Excepteur sint occaecat cupidatat non proident,    **
** sunt in culpa qui officia deserunt mollit anim id est laborum.     **
** At vero eos et accusamus et iusto odio dignissimos ducimus qui     **
** blanditiis praesentium voluptatum deleniti atque corrupti quos     **
** dolores et quas molestias excepturi sint occaecati cupiditate non  **
** provident, similique sunt in culpa qui officia deserunt mollitia   **
** animi, id est laborum et dolorum fuga. Et harum quidem rerum       **
** facilis est et expedita distinctio. Nam libero tempore, cum soluta **
** nobis est eligendi optio cumque nihil impedit quo minus id quod    **
** maxime placeat facere possimus, omnis voluptas assumenda est,      **
** omnis dolor repellendus. Temporibus autem quibusdam et aut         **
** officiis debitis aut rerum necessitatibus saepe eveniet ut et      **
** voluptates repudiandae sint et molestiae non recusandae. Itaque    **
** earum rerum hic tenetur a sapiente delectus, ut aut reiciendis     **
** voluptatibus maiores alias consequatur aut perferendis doloribus   **
** asperiores repellat.                                               **
************************************************************************
"""
        self.assertEqual(wrap_text_in_a_box(text), result)
Example #16
0
    def test_empty_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box empty."""
        result = """
**********************************************
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box(), result)
    def test_real_nothing_at_all_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box nothing at all."""
        result = """
******
******
"""
        self.assertEqual(wrap_text_in_a_box(min_col=0), result)
Example #18
0
 def _display_ask_string_box(self, msg, default=""):
     """Utility to display confirmation boxes."""
     msg = wrap_text_in_a_box(msg, style='no_border')
     rows = msg.split('\n')
     height = len(rows) + 3
     width = max([len(row) for row in rows]) + 4
     self.win = self.curses.newwin(height, width,
                                   (self.height - height) / 2 + 1,
                                   (self.width - width) / 2 + 1)
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     self.win.move(height - 2, 2)
     self.curses.echo()
     for c in reversed(default):
         self.curses.ungetch(c)
     ret = self.win.getstr()
     self.curses.noecho()
     self.panel = None
     return ret
    def test_empty_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box empty."""
        result = """
**********************************************
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box(), result)
    def test_multiline_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box multiline."""
        result = """
**********************************************
** foo bar                                  **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foo\n bar'), result)
    def test_plain_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box plain."""
        result = """
**********************************************
** foo bar                                  **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foo bar'), result)
Example #22
0
    def test_single_new_line_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box single new line."""
        result = """
**********************************************
** ciao come và?                            **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box("ciao\ncome và?"), result)
Example #23
0
    def test_multiline_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box multiline."""
        result = """
**********************************************
** foo bar                                  **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foo\n bar'), result)
Example #24
0
    def test_real_no_width_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box no width."""
        result = """
************
** foobar **
************
"""
        self.assertEqual(wrap_text_in_a_box('foobar', min_col=0), result)
    def test_real_no_width_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box no width."""
        result = """
************
** foobar **
************
"""
        self.assertEqual(wrap_text_in_a_box('foobar', min_col=0), result)
Example #26
0
    def test_plain_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box plain."""
        result = """
**********************************************
** foo bar                                  **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foo bar'), result)
Example #27
0
    def test_indented_box_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box indented box."""
        result = """
    **********************************************
    ** foobar                                   **
    **********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foobar', tab_num=1), result)
    def test_indented_box_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box indented box."""
        result = """
    **********************************************
    ** foobar                                   **
    **********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foobar', tab_num=1), result)
    def test_single_new_line_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box single new line."""
        result = """
**********************************************
** ciao come và?                            **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box("ciao\ncome và?"), result)
Example #30
0
    def test_real_squared_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box squared style."""
        result = """
+--------+
| foobar |
+--------+
"""
        self.assertEqual(wrap_text_in_a_box('foobar', style='squared', min_col=0), result)
def cmd_upgrade(dummy_conf, upgrader=None):
    """ Command for applying upgrades """
    from invenio.config import CFG_LOGDIR
    from invenio.textutils import wrap_text_in_a_box, wait_for_user

    logfilename = os.path.join(CFG_LOGDIR, 'invenio_upgrader.log')
    if not upgrader:
        upgrader = InvenioUpgrader()
    logger = upgrader.get_logger(logfilename=logfilename)

    try:
        upgrades = upgrader.get_upgrades()

        if not upgrades:
            logger.info("All upgrades have been applied.")
            return

        logger.info("Following upgrade(s) will be applied:")

        for u in upgrades:
            title = u['__doc__']
            if title:
                logger.info(" * %s (%s)" % (u['id'], title))
            else:
                logger.info(" * %s" % u['id'])

        logger.info("Running pre-upgrade checks...")
        upgrader.pre_upgrade_checks(upgrades)

        logger.info("Calculating estimated upgrade time...")
        estimate = upgrader.human_estimate(upgrades)

        wait_for_user(wrap_text_in_a_box(
            """WARNING: You are going to upgrade your installation (estimated time: %s)!""" % estimate))

        for u in upgrades:
            title = u['__doc__']
            if title:
                logger.info("Applying %s (%s)" % (u['id'], title))
            else:
                logger.info("Applying %s" % u['id'])
            upgrader.apply_upgrade(u)

        logger.info("Running post-upgrade checks...")
        upgrader.post_upgrade_checks(upgrades)

        if upgrader.has_warnings():
            logger.warning("Upgrade completed with %s warnings - please check "
                           "log-file for further information:\nless %s"
                           % (upgrader.get_warnings_count(), logfilename))
        else:
            logger.info("Upgrade completed successfully.")
    except RuntimeError, e:
        for msg in e.args:
            logger.error(unicode(msg))
        logger.info("Please check log file for further information:\n"
                    "less %s" % logfilename)
        sys.exit(1)
    def test_real_multiline_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box real multiline."""
        result = """
**********************************************
** foo                                      **
** bar                                      **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box("foo\n\nbar"), result)
Example #33
0
    def test_with_title_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box with title."""
        result = """
**********************************************
** a Title!                                 **
** **************************************** **
** foo bar                                  **
**********************************************
"""
        self.assertEqual(wrap_text_in_a_box('foo bar', title='a Title!'), result)
def __print_error(restore_backup=False):
    print wrap_text_in_a_box("The kit encountered errors in migrating passwords. Please contact The Invenio developers in order to get support providing all the printed messages.")
    if restore_backup:
        if __restoring_from_backup():
            print wrap_text_in_a_box("Passwords were restored from the backup, but you still need to migrate them in order to use this version of Invenio.")
        else:
            print wrap_text_in_a_box("The kit was't unable to restore passwords from the backup")
    sys.exit(1)
def __print_error(restore_backup=False):
    print wrap_text_in_a_box("The kit encountered errors in migrating passwords. Please contact The Invenio developers in order to get support providing all the printed messages.")
    if restore_backup:
        if __restoring_from_backup():
            print wrap_text_in_a_box("Passwords were restored from the backup, but you still need to migrate them in order to use this version of Invenio.")
        else:
            print wrap_text_in_a_box("The kit was't unable to restore passwords from the backup")
    sys.exit(1)
Example #36
0
def get_callable_documentation(the_callable):
    """
    Returns a string with the callable signature and its docstring.

    @param the_callable: the callable to be analyzed.
    @type the_callable: function/callable.
    @return: the signature.
    @rtype: string
    """
    return wrap_text_in_a_box(
        title=get_callable_signature_as_string(the_callable),
        body=(getattr(the_callable, '__doc__') or 'No documentation').replace(
            '\n', '\n\n'),
        style='ascii_double')
Example #37
0
def get_callable_documentation(the_callable):
    """
    Returns a string with the callable signature and its docstring.

    @param the_callable: the callable to be analyzed.
    @type the_callable: function/callable.
    @return: the signature.
    @rtype: string
    """
    return wrap_text_in_a_box(
        title=get_callable_signature_as_string(the_callable),
        body=(getattr(the_callable, '__doc__') or 'No documentation').replace(
            '\n', '\n\n'),
        style='ascii_double')
Example #38
0
 def display_task_options(self):
     """Nicely display information about current process."""
     msg = '        id: %i\n\n' % self.currentrow[0]
     pid = get_task_pid(self.currentrow[0])
     if pid is not None:
         msg += '       pid: %s\n\n' % pid
     msg += '  priority: %s\n\n' % self.currentrow[8]
     msg += '      proc: %s\n\n' % self.currentrow[1]
     msg += '      user: %s\n\n' % self.currentrow[2]
     msg += '   runtime: %s\n\n' % self.currentrow[3].strftime("%Y-%m-%d %H:%M:%S")
     msg += ' sleeptime: %s\n\n' % self.currentrow[4]
     msg += '    status: %s\n\n' % self.currentrow[5]
     msg += '  progress: %s\n\n' % self.currentrow[6]
     arguments = marshal.loads(self.currentrow[7])
     if type(arguments) is dict:
         # FIXME: REMOVE AFTER MAJOR RELEASE 1.0
         msg += '   options : %s\n\n' % arguments
     else:
         msg += 'executable : %s\n\n' % arguments[0]
         args_str = ' '.join(arguments[1:])
         if len(args_str) > 500:
             args_str = args_str[:500] + '...'
         msg += ' arguments : %s\n\n' % args_str
     msg += '\n\nPress q to quit this panel...'
     msg = wrap_text_in_a_box(msg, style='no_border', break_long=True)
     rows = msg.split('\n')
     height = len(rows) + 2
     width = max([len(row) for row in rows]) + 4
     try:
         self.win = self.curses.newwin(
             height,
             width,
             (self.height - height) / 2 + 1,
             (self.width - width) / 2 + 1
         )
     except self.curses.error:
         return
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     while self.win.getkey() != 'q':
         pass
     self.panel = None
Example #39
0
def upload_to_site(marcxml, yes_i_know, upload_mode="append"):
    """
    makes the appropriate calls to bibupload to get the MARCXML record onto
    the site. Uploads in "correct" mode.

    @param: marcxml (string): the absolute location of the MARCXML that was
        generated by this programme
    @param: yes_i_know (boolean): if true, no confirmation.  if false, prompt.

    @output: a new record on the invenio site

    @return: None
    """
    if not yes_i_know:
        wait_for_user(wrap_text_in_a_box("You are going to upload new " + "plots to the server."))
    task_low_level_submission("bibupload", "admin", upload_mode and "--" + upload_mode or "", marcxml)
Example #40
0
 def display_task_options(self):
     """Nicely display information about current process."""
     msg = '        id: %i\n\n' % self.currentrow[0]
     pid = get_task_pid(self.currentrow[0])
     if pid is not None:
         msg += '       pid: %s\n\n' % pid
     msg += '  priority: %s\n\n' % self.currentrow[8]
     msg += '      proc: %s\n\n' % self.currentrow[1]
     msg += '      user: %s\n\n' % self.currentrow[2]
     msg += '   runtime: %s\n\n' % self.currentrow[3].strftime(
         "%Y-%m-%d %H:%M:%S")
     msg += ' sleeptime: %s\n\n' % self.currentrow[4]
     msg += '    status: %s\n\n' % self.currentrow[5]
     msg += '  progress: %s\n\n' % self.currentrow[6]
     arguments = marshal.loads(self.currentrow[7])
     if type(arguments) is dict:
         # FIXME: REMOVE AFTER MAJOR RELEASE 1.0
         msg += '   options : %s\n\n' % arguments
     else:
         msg += 'executable : %s\n\n' % arguments[0]
         args_str = ' '.join(arguments[1:])
         if len(args_str) > 500:
             args_str = args_str[:500] + '...'
         msg += ' arguments : %s\n\n' % args_str
     msg += '\n\nPress q to quit this panel...'
     msg = wrap_text_in_a_box(msg, style='no_border', break_long=True)
     rows = msg.split('\n')
     height = len(rows) + 2
     width = max([len(row) for row in rows]) + 4
     try:
         self.win = self.curses.newwin(height, width,
                                       (self.height - height) / 2 + 1,
                                       (self.width - width) / 2 + 1)
     except self.curses.error:
         return
     self.panel = self.curses.panel.new_panel(self.win)
     self.panel.top()
     self.win.border()
     i = 1
     for row in rows:
         self.win.addstr(i, 2, row, self.current_attr)
         i += 1
     self.win.refresh()
     while self.win.getkey() != 'q':
         pass
     self.panel = None
Example #41
0
def upload_to_site(marcxml, yes_i_know):
    """
    makes the appropriate calls to bibupload to get the MARCXML record onto
    the site.

    @param: marcxml (string): the absolute location of the MARCXML that was
        generated by this programme
    @param: yes_i_know (boolean): if true, no confirmation.  if false, prompt.

    @output: a new record on the invenio site

    @return: None
    """
    if not yes_i_know:
        wait_for_user(wrap_text_in_a_box('You are going to upload new ' + \
                                         'plots to the server.'))
    task_low_level_submission('bibupload', 'admin', '-a', marcxml)
Example #42
0
def main():
    """Core loop."""
    check_running_process_user()
    logfilename = '%s/fulltext_files_migration_kit-%s.log' % (CFG_LOGDIR, datetime.today().strftime('%Y%m%d%H%M%S'))
    try:
        logfile = open(logfilename, 'w')
    except IOError, e:
        print wrap_text_in_a_box('NOTE: it\'s impossible to create the log:\n\n  %s\n\nbecause of:\n\n  %s\n\nPlease run this migration kit as the same user who runs Invenio (e.g. Apache)' % (logfilename, e), style='conclusion', break_long=False)
        sys.exit(1)

    bibdoc_bibdoc = retrieve_bibdoc_bibdoc()

    print wrap_text_in_a_box ("""This script migrate the filesystem structure used to store icons files to the new stricter structure.
This script must not be run during normal Invenio operations.
It is safe to run this script. No file will be deleted.
Anyway it is recommended to run a backup of the filesystem structure just in case.
A backup of the database tables involved will be automatically performed.""", style='important')
    if not bibdoc_bibdoc:
        print wrap_text_in_a_box("No need for migration", style='conclusion')
        return
    print "%s icons will be migrated/fixed." % len(bibdoc_bibdoc)
    wait_for_user()
    print "Backing up database tables"
    try:
        if not backup_tables():
            print wrap_text_in_a_box("""It appears that is not the first time that you run this script.
Backup tables have been already created by a previous run.
In order for the script to go further they need to be removed.""", style='important')

            wait_for_user()
def drop(yes_i_know=False):
    """Drops database tables"""

    print ">>> Going to drop tables and related data on filesystem ..."

    from sqlalchemy import event
    from invenio.dateutils import get_time_estimator
    from invenio.textutils import wrap_text_in_a_box, wait_for_user
    from invenio.webstat import destroy_customevents
    from invenio.inveniocfg import test_db_connection
    from invenio.sqlalchemyutils import db
    from invenio.bibdocfile import _make_base_dir

    ## Step 0: confirm deletion
    wait_for_user(
        wrap_text_in_a_box(
            """WARNING: You are going to destroy your database tables and related data on filesystem!"""
        ))

    ## Step 1: test database connection
    test_db_connection()

    ## Step 2: disable foreign key checks
    if db.engine.name == 'mysql':
        db.engine.execute('SET FOREIGN_KEY_CHECKS=0;')

    ## Step 3: destroy associated data
    try:
        msg = destroy_customevents()
        if msg:
            print msg
    except:
        print "ERROR: Could not destroy customevents."

    ## FIXME: move to bibedit_model
    def bibdoc_before_drop(target, connection_dummy, **kw_dummy):
        print
        print ">>> Going to remove records data..."
        for (docid, ) in db.session.query(target.c.id).all():
            directory = _make_base_dir(docid)
            if os.path.isdir(directory):
                print '    >>> Removing files for docid =', docid
                shutil.rmtree(directory)
        db.session.commit()
        print ">>> Data has been removed."

    from invenio.bibedit_model import Bibdoc
    event.listen(Bibdoc.__table__, "before_drop", bibdoc_before_drop)

    tables = list(reversed(db.metadata.sorted_tables))
    N = len(tables)

    prefix = '>>> Dropping %d tables ...' % N

    e = get_time_estimator(N)
    dropped = 0

    for i, table in enumerate(tables):
        try:
            print_progress(1.0 * i / N,
                           prefix=prefix,
                           suffix=str(datetime.timedelta(seconds=e()[0])))
            table.drop(bind=db.engine)
            dropped += 1
        except:
            print '\r', '>>> problem with dropping table', table

    print
    if dropped == N:
        print ">>> Tables dropped successfully."
    else:
        print "ERROR: not all tables were properly dropped."
        print ">>> Dropped", dropped, 'out of', N
Example #44
0
    def test_real_conclusion_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box conclusion."""
        result = """----------------------------------------
foobar                                  \n"""
        self.assertEqual(wrap_text_in_a_box('foobar', style='conclusion'),
                         result)
Example #45
0
def create_config(force=False, no_ssl=True):
    """
    Create Apache configuration files for this site, keeping previous
    files in a backup copy.
    """
    import os
    import pwd
    import sys
    import shutil
    from flask import current_app
    from jinja2 import TemplateNotFound
    from invenio.jinja2utils import render_template_to_string
    from invenio.textutils import wrap_text_in_a_box
    from invenio.access_control_config import CFG_EXTERNAL_AUTH_USING_SSO

    CFG_PREFIX = current_app.config.get('CFG_PREFIX', '')

    def get_context():
        from invenio.inveniocfg import _detect_ip_address

        conf = current_app.config

        ## Apache vhost conf file is distro specific, so analyze needs:
        # Gentoo (and generic defaults):
        listen_directive_needed = True
        ssl_pem_directive_needed = False
        ssl_pem_path = CFG_PREFIX + '/etc/apache/ssl/apache.pem'
        ssl_crt_path = CFG_PREFIX + '/etc/apache/ssl/server.crt'
        ssl_key_path = CFG_PREFIX + '/etc/apache/ssl/server.key'
        vhost_ip_address_needed = False
        wsgi_socket_directive_needed = False
        # Debian:
        if os.path.exists(os.path.sep + 'etc' + os.path.sep +
                          'debian_version'):
            listen_directive_needed = False
            ssl_pem_directive_needed = True
            ssl_pem_path = '/etc/apache2/ssl/apache.pem'
            ssl_crt_path = '/etc/apache2/ssl/server.crt'
            ssl_key_path = '/etc/apache2/ssl/server.key'
        # RHEL/SLC:
        if os.path.exists(os.path.sep + 'etc' + os.path.sep +
                          'redhat-release'):
            listen_directive_needed = False
            ssl_crt_path = '/etc/pki/tls/certs/localhost.crt'
            ssl_key_path = '/etc/pki/tls/private/localhost.key'
            vhost_ip_address_needed = True
            wsgi_socket_directive_needed = True
        # maybe we are using non-standard ports?
        vhost_site_url = conf.get('CFG_SITE_URL').replace("http://", "")
        if vhost_site_url.startswith("https://"):
            ## The installation is configured to require HTTPS for any connection
            vhost_site_url = vhost_site_url.replace("https://", "")
        vhost_site_url_port = '80'
        vhost_site_secure_url = conf.get('CFG_SITE_SECURE_URL').replace(
            "https://", "").replace("http://", "")
        vhost_site_secure_url_port = '443'
        if ':' in vhost_site_url:
            vhost_site_url, vhost_site_url_port = vhost_site_url.split(':', 1)
        if ':' in vhost_site_secure_url:
            vhost_site_secure_url, vhost_site_secure_url_port = vhost_site_secure_url.split(
                ':', 1)
        if vhost_site_url_port != '80' or vhost_site_secure_url_port != '443':
            listen_directive_needed = True

        apc1 = {
            'vhost_site_url_port':
            vhost_site_url_port,
            'servername':
            vhost_site_url,
            'serveralias':
            vhost_site_url.split('.')[0],
            'vhost_ip_address':
            vhost_ip_address_needed and _detect_ip_address() or '*',
            'wsgi_socket_directive_needed':
            wsgi_socket_directive_needed,
            'listen_directive_needed':
            listen_directive_needed,
        }

        apc2 = {
            'vhost_site_url_port':
            vhost_site_secure_url_port,
            'servername':
            vhost_site_secure_url,
            'serveralias':
            vhost_site_secure_url.split('.')[0],
            'vhost_ip_address':
            vhost_ip_address_needed and _detect_ip_address() or '*',
            'wsgi_socket_directive_needed':
            wsgi_socket_directive_needed,
            'ssl_pem_directive':
            ssl_pem_directive_needed and 'SSLCertificateFile %s' % ssl_pem_path
            or '#SSLCertificateFile %s' % ssl_pem_path,
            'ssl_crt_directive':
            ssl_pem_directive_needed
            and '#SSLCertificateFile %s' % ssl_crt_path
            or 'SSLCertificateFile %s' % ssl_crt_path,
            'ssl_key_directive':
            ssl_pem_directive_needed
            and '#SSLCertificateKeyFile %s' % ssl_key_path
            or 'SSLCertificateKeyFile %s' % ssl_key_path,
            'listen_directive_needed':
            listen_directive_needed,
        }

        return [apc1, apc2]

    current_app.config.update(
        CFG_RUNNING_AS_USER=pwd.getpwuid(os.getuid())[0],
        CFG_EXTERNAL_AUTH_USING_SSO=CFG_EXTERNAL_AUTH_USING_SSO,
        CFG_WSGIDIR=os.path.join(CFG_PREFIX, 'var', 'www-wsgi'))

    apache_conf_dir = current_app.config.get('CFG_ETCDIR') + os.sep + 'apache'

    print ">>> Going to create Apache conf files..."
    conf_files = ['invenio-apache-vhost.conf', 'invenio-apache-vhost-ssl.conf']
    conf_files = conf_files[:1 if no_ssl else 2]

    if not os.path.exists(apache_conf_dir):
        os.mkdir(apache_conf_dir)

    for local_file, context in zip(conf_files,
                                   get_context()[:1 if no_ssl else 2]):
        print ">>> Writing %s ..." % local_file

        try:
            apache_vhost_file = apache_conf_dir + os.sep + local_file
            if os.path.exists(apache_vhost_file):
                shutil.copy(apache_vhost_file, apache_vhost_file + '.OLD')

            with open(apache_vhost_file, 'w') as f:
                out = render_template_to_string(local_file + '.tpl',
                                                os=os,
                                                **context)
                print >> f, out

        except TemplateNotFound:
            print >> sys.stderr, "Could not find template %s" % local_file

    print wrap_text_in_a_box("""\
Apache virtual host configuration file(s) for your Invenio site
was(were) created.  Please check created file(s) and activate virtual
host(s).  For example, you can put the following include statements in
your httpd.conf:\n

%s

%s


Please see the INSTALL file for more details.
    """ % tuple(
        map(
            lambda x: "Include " + apache_conf_dir.encode('utf-8') + os.sep +
            x, list(conf_files))))
    print ">>> Apache conf files created."
    def test_real_conclusion_wrap_text_in_a_box(self):
        """textutils - wrap_text_in_a_box conclusion."""
        result = """----------------------------------------
foobar                                  \n"""
        self.assertEqual(wrap_text_in_a_box('foobar', style='conclusion'), result)
Example #47
0
        CFG_LOGDIR, datetime.today().strftime('%Y%m%d%H%M%S'))
    try:
        logfile = open(logfilename, 'w')
    except IOError, e:
        print wrap_text_in_a_box(
            'NOTE: it\'s impossible to create the log:\n\n  %s\n\nbecause of:\n\n  %s\n\nPlease run this migration kit as the same user who runs Invenio (e.g. Apache)'
            % (logfilename, e),
            style='conclusion',
            break_long=False)
        sys.exit(1)

    recids = retrieve_fulltext_recids()
    print wrap_text_in_a_box(
        """This script migrate the filesystem structure used to store fulltext files to the new stricter structure.
This script must not be run during normal Invenio operations.
It is safe to run this script. No file will be deleted.
Anyway it is recommended to run a backup of the filesystem structure just in case.
A backup of the database tables involved will be automatically performed.""",
        style='important')
    print "%s records will be migrated/fixed." % len(recids)
    print "Please type yes if you want to go further:",

    if not check_yes():
        print "INTERRUPTED"
        sys.exit(1)
    print "Backing up database tables"
    try:
        if not backup_tables():
            print wrap_text_in_a_box(
                """It appears that is not the first time that you run this script.
Backup tables have been already created by a previous run.