def handle(self, **options): if options['logger']: logger = logging.getLogger(options['logger']) else: logger = logger_runner if options['debug'] == True: logdebug() logger.debug("options=%s"%options) if options['inerror']: q=CDR.extractinerror.all()[:options['records']] else: if options['force']: q=CDR.extractforce.all()[:options['records']] else: q=CDR.extract.all()[:options['records']] date=datenow().strftime(DATE_FORMAT) try: error=CDR.set_cdr(q, force=options['force']) ret={'info':'Successfully set CDRs %s %s'%(error['cdrs'], error['cdrserror']), 'error':error['error'], 'date':date} except: ret={'info':'Error set CDRs', 'error':traceback.format_exc(), 'date':date} ret=json.dumps(ret) self.stdout.write(ret) return ret
def handle(self, *args, **options): if options['debug'] == True: logdebug() logger.debug("options=%s" % options) self.workdate = datenow() logger.info("WORKDATE %s" % self.workdate) if options['reseller'] is None: lst = Reseller.objects.all() self.stdout.write(40 * '-') for t in lst: self.stdout.write("Reseller %s" % t) self.stdout.write(40 * '-') raise CommandError("Please specifie option reseller") else: try: self.reseller = Reseller.objects.get(pk=options['reseller']) except: self.stdout.write(Reseller.info_resellers()) raise CommandError("Reseller not found") if options['infoconfig'] is None: self.stdout.write(ConfigImport.info_configimport()) raise CommandError("InfoConfig not found") try: self.infoconfig = ConfigImport.objects.get( pk=options['infoconfig']) logger.debug("infoconfig=%s" % self.infoconfig) except (ObjectDoesNotExist, ValueError) as e: logger.error("ConfigImport Info %s %s" % (options['infoconfig'], e)) self.stdout.write(ConfigImport.info_configimport()) raise CommandError("Please specifie option config") if options['filename'] is None: raise CommandError("Filename not found") if options['contrat']: self.myfunc = ie_Customer().import_contrat else: self.myfunc = ie_Customer().import_customer try: self.myfunc(reseller=self.reseller, config=self.infoconfig, filename=options['filename'], force=options['force']) except Exception, e: raise CommandError("%s" % e)
def handle(self, *args, **options): if options['debug'] == True: logdebug() logger.debug("options=%s"%options) self.workdate = datenow() logger.info("WORKDATE %s"%self.workdate) if options['reseller'] is None: lst = Reseller.objects.all() self.stdout.write(40 * '-') for t in lst: self.stdout.write("Reseller %s"%t) self.stdout.write(40 * '-') raise CommandError("Please specifie option reseller") else: try: self.reseller=Reseller.objects.get(pk=options['reseller']) except: self.stdout.write(Reseller.info_resellers()) raise CommandError("Reseller not found") if options['infoconfig'] is None: self.stdout.write(ConfigImport.info_configimport()) raise CommandError("InfoConfig not found") try: self.infoconfig = ConfigImport.objects.get(pk=options['infoconfig']) logger.debug("infoconfig=%s"%self.infoconfig) except (ObjectDoesNotExist, ValueError) as e: logger.error("ConfigImport Info %s %s"%(options['infoconfig'], e)) self.stdout.write(ConfigImport.info_configimport()) raise CommandError("Please specifie option config") if options['filename'] is None: raise CommandError("Filename not found") if options['contrat']: self.myfunc = ie_Customer().import_contrat else: self.myfunc = ie_Customer().import_customer try: self.myfunc(reseller=self.reseller, config=self.infoconfig, filename=options['filename'], force=options['force']) except Exception, e: raise CommandError("%s"%e)
def handle(self, **options): if options['logger']: logger = logging.getLogger(options['logger']) else: logger = logger_runner if options['debug'] == True: logdebug() logger.debug("options=%s" % options) if options['inerror']: q = CDR.extractinerror.all()[:options['records']] else: if options['force']: q = CDR.extractforce.all()[:options['records']] else: q = CDR.extract.all()[:options['records']] date = datenow().strftime(DATE_FORMAT) try: error = CDR.set_cdr(q, force=options['force']) ret = { 'info': 'Successfully set CDRs %s %s' % (error['cdrs'], error['cdrserror']), 'error': error['error'], 'date': date } except: ret = { 'info': 'Error set CDRs', 'error': traceback.format_exc(), 'date': date } ret = json.dumps(ret) self.stdout.write(ret) return ret
def handle(self, *args, **options): if options['debug'] == True: logdebug() logger.debug("options=%s" % options) if options['grilleprice']: options['grillename'] = options['grilleclient'] = False if options['grilleclient']: options['grillename'] = options['grilleprice'] = False self.workdate = datenow() logger.info("WORKDATE %s" % self.workdate) if options['reseller'] is None: lst = Reseller.objects.all() self.stdout.write(40 * '-') for t in lst: self.stdout.write("Reseller %s" % t) self.stdout.write(40 * '-') raise CommandError("Please specifie option reseller") else: try: self.reseller = Reseller.objects.get(pk=options['reseller']) except: self.stdout.write(Reseller.info_resellers()) raise CommandError("Reseller not found") if options['ga'] is None and options['grillename']: lst = GA_Telco.objects.all() self.stdout.write(40 * '-') for t in lst: self.stdout.write("Grille Achat %s" % t) self.stdout.write(40 * '-') raise CommandError("Please specifie option ga") else: if options['ga'] and options['grillename']: try: self.ga = GA_Telco.objects.get(pk=options['ga']) except: self.stdout.write(GA_Telco.info_gas()) raise CommandError("GA_Telco not found") if options['infoconfig'] is None: self.stdout.write(ConfigImport.info_configimport()) raise CommandError("InfoConfig not found") try: self.infoconfig = ConfigImport.objects.get( pk=options['infoconfig']) logger.debug("infoconfig=%s" % self.infoconfig) except (ObjectDoesNotExist, ValueError) as e: logger.error("ConfigImport Info %s %s" % (options['infoconfig'], e)) self.stdout.write(ConfigImport.info_configimport()) raise CommandError("Please specifie option config") if options['filename'] is None: raise CommandError("Filename not found") try: if options['grillename']: ie_Grille().import_grillename(reseller=self.reseller, ga=self.ga, config=self.infoconfig, filename=options['filename'], force=options['force']) if options['grilleprice']: ie_Grille().import_grilleprice(reseller=self.reseller, config=self.infoconfig, filename=options['filename'], force=options['force']) if options['grilleclient']: ie_Grille().import_grilleclient(reseller=self.reseller, config=self.infoconfig, filename=options['filename'], force=options['force']) except Exception, e: raise CommandError("%s" % e)
def handle(self, *args, **options): if getattr(settings, "DEBUG", False): self.djangodebug = True if options["debug"] == True: logdebug() logger.debug("options=%s" % options) self.workdate = datenow() logger.info("WORKDATE %s" % self.workdate) if options["auto"] is False: # automatic, TelcoInjectors par Telco logger.debug("NO AUTO") if options["telco"] is None: lsttelco = Telco.objects.all() self.stdout.write(40 * "-") for t in lsttelco: self.stdout.write("Telco %s" % t) self.stdout.write(40 * "-") raise CommandError("Please specifie option telco") else: try: self.telco = Telco.objects.get(pk=options["telco"]) except ObjectDoesNotExist, e: self.stdout.write(Telco.info_telcos()) raise CommandError("Telco not found") # if options['bizzone'] is None: # logger.error("bizzone \n%s"%info_bizzone()) # raise CommandError("Please specifie option bizzone") if options["injector"] is None: lsttelco = Telco.objects.all() for t in lsttelco: if t.injectors: self.stdout.write(40 * "-") self.stdout.write("Telco %s" % t) for p in t.injectors.all(): self.stdout.write( "Injectors : %s" % "(%s) %s [%s] [%s]" % (int(p.id), p.name, p.get_bizzone_display(), p.get_typeconnexion_display()) ) self.stdout.write(40 * "-") raise CommandError("Please specifie option injector") try: self.telcoinjector = TelcoInjector.objects.get(pk=options["injector"]) logger.debug("injector=%s" % self.telcoinjector) if options["extention"]: self.extention = options["extention"] else: self.extention = self.telcoinjector.get_typefile_display() if options["filename"]: self.thelist = glob.glob(options["filename"]) else: if options["directory"]: self.directory = options["directory"] else: self.directory = normpath(self.telcoinjector.path_dest) logger.debug( "directory=%s extention=%s list=%s" % (self.directory, self.extention, self.get_files(self.directory, self.extention)) ) except ObjectDoesNotExist, e: logger.error("Telco Injector Info %s %s" % (options["injector"], e)) raise CommandError("Please specifie option injector")
def handle(self, *args, **options): ret = {} datefrom = dateto = cdrmanager = None reseller = client = context = None if options['logger']: logger = logging.getLogger(options['logger']) else: logger = logger_runner if options['debug'] == True: logdebug() logger.debug("options=%s"%options) q=None if options["datefrom"]: datefrom = datefromstring(options["datefrom"]+" 00:00:00", short=False) if options["dateto"]: dateto = datefromstring(options["dateto"]+" 23:59:59", short=False) if options["reseller"]: reseller = options["reseller"] if options["client"]: client = options["client"] if options['cdr']: q = CDR.objects.filter(id=options['cdr']) else: if options['context'] == 'Telco': if options['force']==False: cdrmanager = CDR.valo else: cdrmanager = CDR.valoforce else: cdrmanager = CDR.valoresel if datefrom and dateto: q=cdrmanager.filter(sessiondate__range=(datefrom, dateto)) elif datefrom and dateto == None: q=cdrmanager.filter(sessiondate__gte=datefrom) elif datefrom == None and dateto: q=cdrmanager.filter(sessiondate__lte=dateto) else: q=cdrmanager.all() if client or reseller: if client: client = Client.objects.get(code=client) q = q.filter(client=client) if reseller: reseller = Reseller.objects.get(code=reseller) q = q.filter(reseller=reseller) options['context'] = 'Resel' q = q[:options["records"]] cdrcount = q.count() date=datenow() try: error=valo_CDR(context=options['context']).set_valo(q, date=date, logger=logger) ret={'info':'Successfully Valo Resel (nb=%s)'%cdrcount, 'error':error, 'date':date.strftime(DATE_FORMAT)} except: ret={'info':'Error Valo Resel (nb=%s)'%cdrcount, 'error':traceback.format_exc(), 'date':date.strftime(DATE_FORMAT)} ret = json.dumps(ret) self.stdout.write(ret) return ret
def handle(self, *args, **options): if getattr(settings, 'DEBUG', False): self.djangodebug = True if options['debug'] == True: logdebug() logger.debug("options=%s" % options) self.workdate = datenow() logger.info("WORKDATE %s" % self.workdate) if options['auto'] is False: #automatic, TelcoInjectors par Telco logger.debug("NO AUTO") if options['telco'] is None: lsttelco = Telco.objects.all() self.stdout.write(40 * '-') for t in lsttelco: self.stdout.write("Telco %s" % t) self.stdout.write(40 * '-') raise CommandError("Please specifie option telco") else: try: self.telco = Telco.objects.get(pk=options['telco']) except ObjectDoesNotExist, e: self.stdout.write(Telco.info_telcos()) raise CommandError("Telco not found") #if options['bizzone'] is None: # logger.error("bizzone \n%s"%info_bizzone()) # raise CommandError("Please specifie option bizzone") if options['injector'] is None: lsttelco = Telco.objects.all() for t in lsttelco: if t.injectors: self.stdout.write(40 * '-') self.stdout.write("Telco %s" % t) for p in t.injectors.all(): self.stdout.write( "Injectors : %s" % "(%s) %s [%s] [%s]" % (int(p.id), p.name, p.get_bizzone_display(), p.get_typeconnexion_display())) self.stdout.write(40 * '-') raise CommandError("Please specifie option injector") try: self.telcoinjector = TelcoInjector.objects.get( pk=options['injector']) logger.debug("injector=%s" % self.telcoinjector) if options['extention']: self.extention = options['extention'] else: self.extention = self.telcoinjector.get_typefile_display() if options['filename']: self.thelist = glob.glob(options['filename']) else: if options['directory']: self.directory = options['directory'] else: self.directory = normpath(self.telcoinjector.path_dest) logger.debug( "directory=%s extention=%s list=%s" % (self.directory, self.extention, self.get_files(self.directory, self.extention))) except ObjectDoesNotExist, e: logger.error("Telco Injector Info %s %s" % (options['injector'], e)) raise CommandError("Please specifie option injector")
def handle(self, *args, **options): ret = {} datefrom = dateto = cdrmanager = None reseller = client = context = None if options['logger']: logger = logging.getLogger(options['logger']) else: logger = logger_runner if options['debug'] == True: logdebug() logger.debug("options=%s" % options) q = None if options["datefrom"]: datefrom = datefromstring(options["datefrom"] + " 00:00:00", short=False) if options["dateto"]: dateto = datefromstring(options["dateto"] + " 23:59:59", short=False) if options["reseller"]: reseller = options["reseller"] if options["client"]: client = options["client"] if options['cdr']: q = CDR.objects.filter(id=options['cdr']) else: if options['context'] == 'Telco': if options['force'] == False: cdrmanager = CDR.valo else: cdrmanager = CDR.valoforce else: cdrmanager = CDR.valoresel if datefrom and dateto: q = cdrmanager.filter(sessiondate__range=(datefrom, dateto)) elif datefrom and dateto == None: q = cdrmanager.filter(sessiondate__gte=datefrom) elif datefrom == None and dateto: q = cdrmanager.filter(sessiondate__lte=dateto) else: q = cdrmanager.all() if client or reseller: if client: client = Client.objects.get(code=client) q = q.filter(client=client) if reseller: reseller = Reseller.objects.get(code=reseller) q = q.filter(reseller=reseller) options['context'] = 'Resel' q = q[:options["records"]] cdrcount = q.count() date = datenow() try: error = valo_CDR(context=options['context']).set_valo( q, date=date, logger=logger) ret = { 'info': 'Successfully Valo Resel (nb=%s)' % cdrcount, 'error': error, 'date': date.strftime(DATE_FORMAT) } except: ret = { 'info': 'Error Valo Resel (nb=%s)' % cdrcount, 'error': traceback.format_exc(), 'date': date.strftime(DATE_FORMAT) } ret = json.dumps(ret) self.stdout.write(ret) return ret
def doit(): workdate = datenow() ret = {'info': '(site %s) Successfully Debug'%the_site(), 'error':'', 'date':workdate.strftime(DATE_FORMAT)} logger.info(ret) return ret
def handle(self, *args, **options): if options["debug"] == True: logdebug() logger.debug("options=%s" % options) if options["grilleprice"]: options["grillename"] = options["grilleclient"] = False if options["grilleclient"]: options["grillename"] = options["grilleprice"] = False self.workdate = datenow() logger.info("WORKDATE %s" % self.workdate) if options["reseller"] is None: lst = Reseller.objects.all() self.stdout.write(40 * "-") for t in lst: self.stdout.write("Reseller %s" % t) self.stdout.write(40 * "-") raise CommandError("Please specifie option reseller") else: try: self.reseller = Reseller.objects.get(pk=options["reseller"]) except: self.stdout.write(Reseller.info_resellers()) raise CommandError("Reseller not found") if options["ga"] is None and options["grillename"]: lst = GA_Telco.objects.all() self.stdout.write(40 * "-") for t in lst: self.stdout.write("Grille Achat %s" % t) self.stdout.write(40 * "-") raise CommandError("Please specifie option ga") else: if options["ga"] and options["grillename"]: try: self.ga = GA_Telco.objects.get(pk=options["ga"]) except: self.stdout.write(GA_Telco.info_gas()) raise CommandError("GA_Telco not found") if options["infoconfig"] is None: self.stdout.write(ConfigImport.info_configimport()) raise CommandError("InfoConfig not found") try: self.infoconfig = ConfigImport.objects.get(pk=options["infoconfig"]) logger.debug("infoconfig=%s" % self.infoconfig) except (ObjectDoesNotExist, ValueError) as e: logger.error("ConfigImport Info %s %s" % (options["infoconfig"], e)) self.stdout.write(ConfigImport.info_configimport()) raise CommandError("Please specifie option config") if options["filename"] is None: raise CommandError("Filename not found") try: if options["grillename"]: ie_Grille().import_grillename( reseller=self.reseller, ga=self.ga, config=self.infoconfig, filename=options["filename"], force=options["force"], ) if options["grilleprice"]: ie_Grille().import_grilleprice( reseller=self.reseller, config=self.infoconfig, filename=options["filename"], force=options["force"] ) if options["grilleclient"]: ie_Grille().import_grilleclient( reseller=self.reseller, config=self.infoconfig, filename=options["filename"], force=options["force"] ) except Exception, e: raise CommandError("%s" % e)
class Command(BaseCommand): """ TODO: Doc """ help = 'Import fichier tarif achat opérateur' option_list = BaseCommand.option_list + ( make_option( '--telco', action='store', dest='telco', help=_(u'Telco id')), make_option('--config', action='store', dest='infoconfig', help=_(u'InfoConfig id')), make_option( '--bizzone', action='store', dest='bizzone', help='Bizzone Code'), make_option( '--typezone', action='store', dest='typezone', help='TypeZone id'), make_option( '--filename', action='store', dest='filename', help='File name'), make_option('--force', action='store_true', dest='force', default=False, help='Force update price info'), make_option('--debug', action='store_true', dest='debug', default=False, help='Debug log'), ) telco = None infoconfig = None workdate = datenow() def handle(self, *args, **options): if options['debug'] == True: logdebug() logger.debug("options=%s" % options) if options['telco'] is None: lsttelco = Telco.objects.all() self.stdout.write(40 * '-') for t in lsttelco: self.stdout.write("Telco %s" % t) self.stdout.write(40 * '-') raise CommandError("Please specifie option telco") else: try: self.telco = Telco.objects.get(pk=options['telco']) except: self.stdout.write(Telco.info_telcos()) raise CommandError("Telco not found") if options['typezone'] is None or not options[ 'typezone'] in list_typezone(): logger.error("typezone \n%s" % info_typezone()) raise CommandError("Please specifie option typezone") # if options['bizzone'] is None: # logger.error("bizzone \n%s"%info_bizzone()) # raise CommandError("Please specifie option bizzone") if options['infoconfig'] is None: self.stdout.write(ConfigImport.info_configimport()) raise CommandError("InfoConfig not found") try: self.infoconfig = ConfigImport.objects.get( pk=options['infoconfig']) logger.debug("infoconfig=%s" % self.infoconfig) except (ObjectDoesNotExist, ValueError) as e: logger.error("ConfigImport Info %s %s" % (options['infoconfig'], e)) self.stdout.write(ConfigImport.info_configimport()) raise CommandError("Please specifie option config") if options['filename'] is None: raise CommandError("Filename not found") try: ie_Price().import_price(type=options['typezone'], fromtelco=self.telco, config=self.infoconfig, filename=options['filename'], force=options['force']) except Exception, e: raise CommandError("%s" % e) self.stdout.write('Successfully import price file %s' % options['filename'])