|
1 # Copyright (C) 2005, Giovanni Bajo |
|
2 # Based on previous work under copyright (c) 1999, 2002 McMillan Enterprises, Inc. |
|
3 # |
|
4 # This program is free software; you can redistribute it and/or |
|
5 # modify it under the terms of the GNU General Public License |
|
6 # as published by the Free Software Foundation; either version 2 |
|
7 # of the License, or (at your option) any later version. |
|
8 # |
|
9 # This program is distributed in the hope that it will be useful, |
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 # GNU General Public License for more details. |
|
13 # |
|
14 # You should have received a copy of the GNU General Public License |
|
15 # along with this program; if not, write to the Free Software |
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
17 |
|
18 #import pythoncom |
|
19 pycomCLSCTX_INPROC = 3 |
|
20 pycomCLSCTX_LOCAL_SERVER = 4 |
|
21 import os |
|
22 d = {} |
|
23 |
|
24 class NextID: |
|
25 _reg_clsid_ = '{25E06E61-2D18-11D5-945F-00609736B700}' |
|
26 _reg_desc_ = 'Text COM server' |
|
27 _reg_progid_ = 'MEInc.NextID' |
|
28 _reg_clsctx_ = pycomCLSCTX_INPROC | pycomCLSCTX_LOCAL_SERVER |
|
29 _public_methods_ = [ |
|
30 'getNextID' |
|
31 ] |
|
32 def __init__(self): |
|
33 import win32api |
|
34 win32api.MessageBox(0, "NextID.__init__ started", "NextID.py") |
|
35 global d |
|
36 if sys.frozen: |
|
37 for entry in sys.path: |
|
38 if entry.find('?') > -1: |
|
39 here = os.path.dirname(entry.split('?')[0]) |
|
40 break |
|
41 else: |
|
42 here = os.getcwd() |
|
43 else: |
|
44 here = os.path.dirname(__file__) |
|
45 self.fnm = os.path.join(here, 'id.cfg') |
|
46 try: |
|
47 d = eval(open(self.fnm, 'r').read()+'\n') |
|
48 except: |
|
49 d = { |
|
50 'systemID': 0xaaaab, |
|
51 'highID': 0 |
|
52 } |
|
53 win32api.MessageBox(0, "NextID.__init__ complete", "NextID.py") |
|
54 def getNextID(self): |
|
55 global d |
|
56 d['highID'] = d['highID'] + 1 |
|
57 open(self.fnm, 'w').write(repr(d)) |
|
58 return '%(systemID)-0.5x%(highID)-0.7x' % d |
|
59 |
|
60 def RegisterNextID(): |
|
61 from win32com.server import register |
|
62 register.UseCommandLine(NextID) |
|
63 |
|
64 def UnRegisterNextID(): |
|
65 from win32com.server import register |
|
66 register.UnregisterServer(NextID._reg_clsid_, NextID._reg_progid_) |
|
67 |
|
68 if __name__ == '__main__': |
|
69 import sys |
|
70 if "/unreg" in sys.argv: |
|
71 UnRegisterNextID() |
|
72 elif "/register" in sys.argv: |
|
73 RegisterNextID() |
|
74 else: |
|
75 print "running as server" |
|
76 import win32com.server.localserver |
|
77 win32com.server.localserver.main() |
|
78 raw_input("Press any key...") |
|
79 |