コード例 #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()
コード例 #2
0
    def test_contact(self):
        entry = gammu.ReadBackup(os.path.join(
            TEST_DIR, 'gammu.vcf'))['PhonePhonebook'][0]

        # Convert it to vCard
        vc_entry = gammu.EncodeVCARD(entry)

        # Convert it back to entry
        entry2 = gammu.DecodeVCARD(vc_entry)

        self.assertEqual(entry, entry2)
コード例 #3
0
    def test_todo(self):
        entry = gammu.ReadBackup(os.path.join(TEST_DIR, '02.vcs'))['ToDo'][0]

        # Convert it to vCard
        vt_entry = gammu.EncodeVTODO(entry)
        it_entry = gammu.EncodeITODO(entry)

        # Convert it back to entry
        entry2 = gammu.DecodeVCS(vt_entry)
        entry3 = gammu.DecodeICS(it_entry)

        self.assertEqual(entry2['Type'], entry3['Type'])
コード例 #4
0
    def test_calendar(self):
        entry = gammu.ReadBackup(os.path.join(TEST_DIR,
                                              'rrule.ics'))['Calendar'][0]

        # Convert it to vCard
        vc_entry = gammu.EncodeVCALENDAR(entry)
        ic_entry = gammu.EncodeICALENDAR(entry)

        # Convert it back to entry
        entry2 = gammu.DecodeVCS(vc_entry)
        entry3 = gammu.DecodeICS(ic_entry)

        self.assertEqual(entry2['Type'], entry3['Type'])
コード例 #5
0
ファイル: addcontacts.py プロジェクト: kiiway/Python-PWM-SMS
def main():
    if len(sys.argv) != 3:
        print('This requires two parameters: '
              'memory_type and backup file (eg. vcard)!')
        sys.exit(1)

    state_machine = gammu.StateMachine()
    state_machine.ReadConfig()
    state_machine.Init()

    memory = sys.argv[1]
    filename = sys.argv[2]

    backup = gammu.ReadBackup(filename)

    for item in backup['PhonePhonebook']:
        item['MemoryType'] = memory
        loc = state_machine.AddMemory(item)
        print(('Added item to location {0:d}'.format(loc)))
コード例 #6
0
# 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)
コード例 #7
0
ファイル: addcontacts.py プロジェクト: bangnaga/nokiomane
#!/usr/bin/env python

import gammu
import sys

if len(sys.argv) != 3:
    print 'This requires two parameters: memory_type and backup file (eg. vcard)!'
    sys.exit(1)

sm = gammu.StateMachine()
sm.ReadConfig()
sm.Init()

memory = sys.argv[1]
filename = sys.argv[2]

backup = gammu.ReadBackup(filename)

for item in backup['PhonePhonebook']:
    item['MemoryType'] = memory
    loc = sm.AddMemory(item)
    print 'Added item to location %d' % loc