def cmd_customers(opts, args, overDict): def _wait_remove_customer_and_stop(src, customer_name, count=0): customers = [] for s in find_comments(src): if s.count('[online ]') or s.count('[offline]'): customers.append(s[18:38].strip()) if customer_name not in customers: print ' customer %s is removed !' % customer_name print_and_stop(src) return if count >= 20: print ' time is out\n' reactor.stop() return else: def _check_again(customer_name, count): sys.stdout.write('.') run_url_command(webcontrol._PAGE_CUSTOMERS).addCallback(_wait_remove_customer_and_stop, customer_name, count) reactor.callLater(1, _check_again, customer_name, count+1) if len(args) < 2 or args[1] in [ 'list', 'ls', ]: url = webcontrol._PAGE_CUSTOMERS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'call', 'cl', ]: url = webcontrol._PAGE_CUSTOMERS + '?action=call' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'remove', 'rm', ] and len(args) >= 3: contacts.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contacts.getCustomerID(int(idurl)) except: idurl = 'http://'+settings.IdentityServerName()+'/'+idurl+'.xml' name = nameurl.GetName(idurl) url = webcontrol._PAGE_CUSTOMERS + '?action=remove&idurl=%s' % misc.pack_url_param(idurl) run_url_command(url).addCallback(_wait_remove_customer_and_stop, name, 0) reactor.run() return 0 return 2
def init_contacts(callback=None, errback=None): """ Initialize `contacts` and `identitycache`. """ dhnio.Dprint(2, "dhninit.init_contacts") import lib.misc as misc misc.loadLocalIdentity() if misc._LocalIdentity is None: if errback is not None: errback(1) return import lib.contacts as contacts contacts.init() import lib.identitycache as identitycache identitycache.init(callback, errback)
def cmd_suppliers(opts, args, overDict): def _wait_replace_supplier_and_stop(src, supplier_name, count=0): suppliers = [] for s in find_comments(src): if s.count('[online ]') or s.count('[offline]'): suppliers.append(s[18:38].strip()) if supplier_name not in suppliers: print ' supplier %s is fired !' % supplier_name print_and_stop(src) return if count >= 20: print ' time is out\n' reactor.stop() return else: def _check_again(supplier_name, count): sys.stdout.write('.') run_url_command(webcontrol._PAGE_SUPPLIERS).addCallback(_wait_replace_supplier_and_stop, supplier_name, count) reactor.callLater(1, _check_again, supplier_name, count+1) if len(args) < 2 or args[1] in [ 'list', 'ls' ]: url = webcontrol._PAGE_SUPPLIERS run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'call', 'cl' ]: url = webcontrol._PAGE_SUPPLIERS + '?action=call' run_url_command(url).addCallback(print_and_stop) reactor.run() return 0 elif args[1] in [ 'replace', 'rep', 'rp' ] and len(args) >= 3: contacts.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contacts.getSupplierID(int(idurl)) except: idurl = 'http://'+settings.IdentityServerName()+'/'+idurl+'.xml' if not idurl: print 'supplier IDURL is None\n' return 0 name = nameurl.GetName(idurl) url = webcontrol._PAGE_SUPPLIERS + '?action=replace&idurl=%s' % misc.pack_url_param(idurl) run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0) reactor.run() return 0 elif args[1] in [ 'change', 'ch' ] and len(args) >= 4: contacts.init() idurl = args[2].strip() if not idurl.startswith('http://'): try: idurl = contacts.getSupplierID(int(idurl)) except: idurl = 'http://'+settings.IdentityServerName()+'/'+idurl+'.xml' if not idurl: print 'supplier IDURL is None\n' return 0 newidurl = args[3].strip() if not newidurl.startswith('http://'): newidurl = 'http://'+settings.IdentityServerName()+'/'+newidurl+'.xml' name = nameurl.GetName(idurl) newname = nameurl.GetName(newidurl) url = webcontrol._PAGE_SUPPLIERS + '?action=change&idurl=%s&newidurl=%s' % (misc.pack_url_param(idurl), misc.pack_url_param(newidurl)) run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0) reactor.run() return 0 return 2
# print pathID, misc.unicode_to_str_safe(localPath) # backup_fs.TraverseByIDSorted(lambda x, y, z: sys.stdout.write('%s %s\n' % (x,misc.unicode_to_str_safe(y)))) def test2(): """ For tests. """ # reactor.callLater(1, StartDirRecursive, 'c:/temp') reactor.run() #------------------------------------------------------------------------------ if __name__ == "__main__": dhnio.init() dhnio.SetDebug(20) settings.init() tmpfile.init(settings.getTempDir()) contacts.init() eccmap.init() dhncrypto.InitMyKey() init() test()