示例#1
0
    def perform_test(self, filename, extensions):
        out_files = [
            tempfile.NamedTemporaryFile(suffix=extension)
            for extension in extensions
        ]
        out_backup = tempfile.NamedTemporaryFile(suffix='.backup')
        try:
            backup = gammu.ReadBackup(filename)
            for out in out_files:
                # Save to new format
                gammu.SaveBackup(out.name, backup)

                # Parse created file
                backup_2 = gammu.ReadBackup(out.name)

                # Check content length
                self.assertEqual(
                    len(backup['Calendar']), len(backup_2['Calendar']),
                    'Failed to compare calendar in {0}'.format(filename))
                self.assertEqual(
                    len(backup['PhonePhonebook']) +
                    len(backup['SIMPhonebook']),
                    len(backup_2['PhonePhonebook']) +
                    len(backup_2['SIMPhonebook']),
                    'Failed to compare phonebook in {0}'.format(filename))

                # Try converting to .backup
                gammu.SaveBackup(out_backup.name, backup)
        finally:
            for handle in out_files:
                handle.close()
            out_backup.close()
# Copyright © 2003 - 2018 Michal Čihař <*****@*****.**>
#
# This file is part of python-gammu <https://wammu.eu/python-gammu/>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from __future__ import print_function
import gammu

import sys
if len(sys.argv) != 3:
    print('This requires two parameter with file names!'
          ' First is input, second output.')
    sys.exit(1)

backup = gammu.ReadBackup(sys.argv[1])
gammu.SaveBackup(sys.argv[2], backup)