Files
@ f52920fe83b5
Branch filter:
Location: rattail-project/rattail/rattail/palm.py
f52920fe83b5
5.4 KiB
text/x-python
Added Palm OS app interface.
This commit adds the Palm HotSync conduit, which is used to create CSV
files when a handheld running the Rattail app is synced with its
desktop PC.
This commit adds the Palm HotSync conduit, which is used to create CSV
files when a handheld running the Rattail app is synced with its
desktop PC.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail 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 Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``rattail.palm`` -- Palm OS Application Interface
"""
import os
import os.path
import socket
import getpass
import datetime
import logging
import edbob
import rattail
from rattail.csvutil import DictWriter
# Hack for docs' sake (building on Linux).
try:
import pythoncom
except ImportError:
pythoncom = object()
pythoncom.CLSCTX_LOCAL_SERVER = 4
log = logging.getLogger(__name__)
class PalmConduit(object):
"""
Implements a conduit for Palm's Hotsync Manager.
"""
_reg_clsid_ = '{F2FDDEEC-254F-42C3-8801-C41E8A243F13}'
_reg_progid_ = 'Rattail.PalmConduit'
_reg_desc_ = "Rattail Conduit for Palm Hotsync Manager"
# Don't let pythoncom guess this, for several reasons. This way Python
# will go about determining its path etc. as normal, and __name__ will be
# "rattail.palm" instead of just "palm".
_reg_class_spec_ = 'rattail.palm.PalmConduit'
# Don't let Hotsync Manager run our code in-process, so that we may launch
# wxPython dialogs as needed for configuration etc.
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
_typelib_guid_ = '{6FD7A7A0-FA1F-11D2-AC32-006008E3F0A2}'
_typelib_version_ = 1, 0
_com_interfaces_ = ['IPDClientNotify']
_public_methods_ = ['BeginProcess', 'CfgConduit',
'ConfigureConduit', 'GetConduitInfo']
def BeginProcess(self):
"""
Called by Hotsync Manager when synchronization is ready to happen.
This method implements the actual data sync.
"""
from win32com.client import Dispatch
edbob.init('rattail')
data_dir = edbob.config.require('rattail.palm', 'collection_dir')
if not os.path.exists(data_dir):
os.makedirs(data_dir)
db_query = Dispatch('PDDirect.PDDatabaseQuery')
db = db_query.OpenRecordDatabase('Rattail_Scan', 'PDDirect.PDRecordAdapter')
if db.RecordCount:
sys_adapter = Dispatch('PDDirect.PDSystemAdapter')
fname = '%s,%s,%s,%s.csv' % (socket.gethostname(), getpass.getuser(),
sys_adapter.PDUserInfo.UserName,
datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S'))
data_path = os.path.join(data_dir, fname)
log.info("PalmConduit.BeginProcess: writing %u handheld records to file: %s" %
(db.RecordCount, data_path))
data_file = open(data_path, 'wb')
writer = DictWriter(data_file, ['upc', 'cases', 'units'])
writer.writeheader()
for i in range(db.RecordCount):
rec, unique_id, category, attrs = db.ReadByIndex(i)
writer.writerow({
'upc': rec[:15].rstrip('\x00'),
'cases': rec[15:19].rstrip('\x00'),
'units': rec[19:23].rstrip('\x00'),
})
data_file.close()
log.info("PalmConduit.BeginProcess: removing all records from handheld")
db.RemoveSet(0)
log.info("PalmConduit.BeginProcess: done")
else:
log.info("PalmConduit.BeginProcess: nothing to do")
return False
def CfgConduit(self, nCreatorId, nUserId, bstrUserName, bstrPathName,
nSyncPerm, nSyncTemp, nSyncNew, nSyncPref):
pass
def ConfigureConduit(self, pPathName, pRegistry, nSyncPref, nSyncType):
pass
def GetConduitInfo(self, infoType, dwCreatorID, dwUserID, bstrUsername):
return None
def register_conduit():
"""
Registers the conduit with Palm Hotsync Manager.
"""
import pywintypes
from win32com.client import Dispatch
conduit_mgr = Dispatch('PDStandard.PDSystemCondMgr')
creator_id = conduit_mgr.StringToCreatorID('RTTL')
assert creator_id
try:
info = conduit_mgr.GetConduitInfo(creator_id)
except pywintypes.com_error:
pass
else:
return # already registered
info = Dispatch('PDStandard.PDConduitInfo')
info.COMClassID = 'Rattail.PalmConduit'
info.CreatorID = creator_id
info.DesktopDataDirectory = 'Rattail'
info.DisplayName = 'Rattail'
conduit_mgr.RegisterConduit(info)
def unregister_conduit():
"""
Unregisters the conduit from Hotsync Manager.
"""
from win32com.client import Dispatch
conduit_mgr = Dispatch('PDStandard.PDSystemCondMgr')
creator_id = conduit_mgr.StringToCreatorID('RTTL')
assert creator_id
conduit_mgr.UnregisterConduit(creator_id)
|