Example #1
0
def run(files, backup=True):
    """
    Runs the migration process

        @param files A list of files to migrate
        @param backup If true, the files are backed up before running the migration. The
                      backup file is the filename plus '.mantidbackup'
    """
    if len(files) == 0:
        messages.notify("Nothing to do!")
        return 0
    if type(files) == str:
        files = [files]

    reports = []
    for filename in files:
        script = ScriptFile(filename, backup)
        try:
            msg = script.migrate()
        except Exception, exc:
            traceback.print_exc()
            script.restore_backup()
            msg = "%s: Backup restored." % (filename)
        reports.append(msg)
        del script
Example #2
0
def run(files, backup=True):
    """
    Runs the migration process

        @param files A list of files to migrate
        @param backup If true, the files are backed up before running the migration. The
                      backup file is the filename plus '.mantidbackup'
    """
    if len(files) == 0:
        messages.notify("Nothing to do!")
        return 0
    if type(files) == str:
        files = [files]

    reports = []
    for filename in files:
        script = ScriptFile(filename, backup)
        try:
            msg = script.migrate()
        except Exception, exc:
            traceback.print_exc()
            script.restore_backup()
            msg = "%s: Backup restored." % (filename)
        reports.append(msg)
        del script
Example #3
0
 def restore_backup(self):
     """
     Copies the file from the backup to the original
     location
     """
     if not self.dobackup:
         messages.notify("Cannot restore from backup, no backup was requested")
     if os.path.exists(self.backup_filename):
         shutil.copy(self.backup_filename, self.filename)
Example #4
0
 def backup(self):
     """
     Backup the file by copying it to
     a different filename with the
     extension defined by self.backup_ext
     """
     if self.dobackup and self.filename is not None:
         messages.notify("Backing up %s to %s" % (self.filename, self.backup_filename))
         shutil.copy(self.filename, self.backup_filename)
Example #5
0
 def restore_backup(self):
     """
     Copies the file from the backup to the original
     location
     """
     if not self.dobackup:
         messages.notify(
             "Cannot restore from backup, no backup was requested")
     if os.path.exists(self.backup_filename):
         shutil.copy(self.backup_filename, self.filename)
Example #6
0
 def backup(self):
     """
     Backup the file by copying it to
     a different filename with the
     extension defined by self.backup_ext
     """
     if self.dobackup and self.filename is not None:
         messages.notify("Backing up %s to %s" %
                         (self.filename, self.backup_filename))
         shutil.copy(self.filename, self.backup_filename)
Example #7
0
    if type(files) == str:
        files = [files]

    reports = []
    for filename in files:
        script = ScriptFile(filename, backup)
        try:
            msg = script.migrate()
        except Exception, exc:
            traceback.print_exc()
            script.restore_backup()
            msg = "%s: Backup restored." % (filename)
        reports.append(msg)
        del script

    messages.notify("\n" + "="*10 + " Report " + "="*10 + "\n")
    for report in reports:
        messages.notify(str(report))

    return 0


class ScriptFile(object):
    """
    Encapsulates a script file. The migration
    process can be run by calling migrate
    """
    _filename = None
    dobackup = True
    backup_ext = '.mantidbackup'
    backup_filename = None
Example #8
0
    if type(files) == str:
        files = [files]

    reports = []
    for filename in files:
        script = ScriptFile(filename, backup)
        try:
            msg = script.migrate()
        except Exception, exc:
            traceback.print_exc()
            script.restore_backup()
            msg = "%s: Backup restored." % (filename)
        reports.append(msg)
        del script

    messages.notify("\n" + "=" * 10 + " Report " + "=" * 10 + "\n")
    for report in reports:
        messages.notify(str(report))

    return 0


class ScriptFile(object):
    """
    Encapsulates a script file. The migration
    process can be run by calling migrate
    """
    _filename = None
    dobackup = True
    backup_ext = '.mantidbackup'
    backup_filename = None