def ListCustomerFiles1(customerNumber): idurl = contacts.getCustomerID(customerNumber) filename = nameurl.UrlFilename(idurl) customerDir = os.path.join(settings.getCustomersFilesDir(), filename) if os.path.exists(customerDir) and os.path.isdir(customerDir): backupFilesList = os.listdir(customerDir) if len(backupFilesList) > 0: return ListSummary(backupFilesList) return "No files stored for this customer"
def _send(index, payload, delay): global _SlowSendIsWorking idurl = contacts.getCustomerID(index) if not idurl: _SlowSendIsWorking = False return transport_control.ClearAliveTime(idurl) SendToID(idurl, Payload=payload, wide=True) reactor.callLater(delay, _send, index+1, payload, delay)
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 SendReplaceCustomer(numORidurl, doAck=False): """ Send "FireContact" packet to Central server to remove a customer. This man will need to find a new supplier. Central server will do that automatically. """ if isinstance(numORidurl, str): idurl = numORidurl else: idurl = contacts.getCustomerID(numORidurl) if not idurl: dhnio.Dprint(2, "central_service.SendReplaceCustomer ERROR customer not found") return None dhnio.Dprint(4, "central_service.SendReplaceCustomer [%s]" % nameurl.GetName(idurl)) data = 'C\n'+idurl+'\n'+str(contacts.numberForCustomer(idurl)) ret = send2central(commands.FireContact(), data, doAck) events.notify('central_service', 'sent request to dismiss customer %s' % nameurl.GetName(idurl)) return ret