Exemplo n.º 1
0
def filenameIN(basename=None):
    """
    File name for incoming stats for today or other day.
    """
    if basename is None:
        basename = misc.gmtime2str('%d%m%y')
    return os.path.join(settings.BandwidthInDir(), basename)
Exemplo n.º 2
0
def filenameOUT(basename=None):
    """
    File name for outgoing stats for today or other day.
    """
    if basename is None:
        basename = misc.gmtime2str('%d%m%y')
    return os.path.join(settings.BandwidthOutDir(), basename)
Exemplo n.º 3
0
def files2send():
    """
    Return a list of file names to be read and send later.

    Sent files are market with ".sent" extension and skipped here.
    """
    lg.out(6, 'bandwidth.files2send')
    listIN = []
    listOUT = []
    for filename in os.listdir(settings.BandwidthInDir()):
        # if we sent the file - skip it
        if filename.endswith('.sent'):
            continue
        # if filename is not a date - skip it
        if len(filename) != 6:
            continue
        # skip today bandwidth - it is still counting, right?
        if filename == misc.gmtime2str('%d%m%y'):
            continue
        filepath = os.path.join(settings.BandwidthInDir(), filename)
        # if filepath == filenameIN():
        #     continue
        listIN.append(filepath)
    for filename in os.listdir(settings.BandwidthOutDir()):
        if filename.endswith('.sent'):
            continue
        if len(filename) != 6:
            continue
        if filename == misc.gmtime2str('%d%m%y'):  # time.strftime('%d%m%y'):
            continue
        filepath = os.path.join(settings.BandwidthOutDir(), filename)
        # if filepath == filenameOUT():
        #     continue
        listOUT.append(filepath)
    lg.out(
        6, 'bandwidth.files2send listIN=%d listOUT=%d' %
        (len(listIN), len(listOUT)))
    for i in listIN:
        lg.out(6, '  ' + i)
    for i in listOUT:
        lg.out(6, '  ' + i)
    return listIN, listOUT
Exemplo n.º 4
0
def files2send():
    """
    Return a list of file names to be read and send later.

    Sent files are market with ".sent" extension and skipped here.
    """
    lg.out(6, 'bandwidth.files2send')
    listIN = []
    listOUT = []
    for filename in os.listdir(settings.BandwidthInDir()):
        # if we sent the file - skip it
        if filename.endswith('.sent'):
            continue
        # if filename is not a date - skip it
        if len(filename) != 6:
            continue
        # skip today bandwidth - it is still counting, right?
        if filename == misc.gmtime2str('%d%m%y'):
            continue
        filepath = os.path.join(settings.BandwidthInDir(), filename)
        # if filepath == filenameIN():
        #     continue
        listIN.append(filepath)
    for filename in os.listdir(settings.BandwidthOutDir()):
        if filename.endswith('.sent'):
            continue
        if len(filename) != 6:
            continue
        if filename == misc.gmtime2str('%d%m%y'):  # time.strftime('%d%m%y'):
            continue
        filepath = os.path.join(settings.BandwidthOutDir(), filename)
        # if filepath == filenameOUT():
        #     continue
        listOUT.append(filepath)
    lg.out(6, 'bandwidth.files2send listIN=%d listOUT=%d' % (len(listIN), len(listOUT)))
    for i in listIN:
        lg.out(6, '  ' + i)
    for i in listOUT:
        lg.out(6, '  ' + i)
    return listIN, listOUT
Exemplo n.º 5
0
def saveOUT(basename=None):
    """
    Writes outgoing stats for today on disk.
    """
    if basename is None:
        basename = misc.gmtime2str('%d%m%y')
    ret = os.path.isfile(filenameOUT(basename))
    bpio._write_dict(filenameOUT(basename), getBandwidthOUT())
    if not ret:
        lg.out(4, 'bandwidth.saveOUT to new file ' + basename)
    else:
        lg.out(22, 'bandwidth.saveOUT to ' + basename)
    return ret
Exemplo n.º 6
0
def saveOUT(basename=None):
    """
    Writes outgoing stats for today on disk.
    """
    if basename is None:
        basename = misc.gmtime2str('%d%m%y')
    ret = os.path.isfile(filenameOUT(basename))
    bpio._write_dict(filenameOUT(basename), getBandwidthOUT())
    if not ret:
        lg.out(4, 'bandwidth.saveOUT to new file ' + basename)
    else:
        lg.out(22, 'bandwidth.saveOUT to ' + basename)
    return ret
Exemplo n.º 7
0
def OUT(idurl, size):
    """
    Call this when need to count outgoing bandwidth.

    ``size`` - how many bytes sent to user with ``idurl``.
    Typically called when outgoing packet were sent.
    """
    global BandOutDict
    global CountTimeOut
    if not isExistOUT():
        currentFileName = time.strftime('%d%m%y', time.localtime(CountTimeOut))
        if currentFileName != misc.gmtime2str('%d%m%y'):
            saveOUT(currentFileName)
            clear_bandwidthOUT()
            CountTimeOut = time.time()
    currentV = int(BandOutDict.get(idurl, 0))
    newV = currentV + size
    BandOutDict[idurl] = newV
    curMB = int(currentV / (1024.0 * 1024.0))
    newMB = int(newV / (1024.0 * 1024.0))
    if curMB == 0 or curMB != newMB:
        saveOUT()
Exemplo n.º 8
0
def IN(idurl, size):
    """
    Call this when need to count incoming bandwidth.

    ``size`` - how many incoming bytes received from user with ``idurl``.
    Typically called when incoming packet arrives.
    """
    global BandInDict
    global CountTimeIn
    if not isExistIN():
        currentFileName = time.strftime('%d%m%y', time.localtime(CountTimeIn))
        if currentFileName != misc.gmtime2str('%d%m%y'):
            saveIN(currentFileName)
            clear_bandwidthIN()
            CountTimeIn = time.time()
    currentV = int(BandInDict.get(idurl, 0))
    newV = currentV + size
    BandInDict[idurl] = newV
    curMB = int(currentV / (1024.0 * 1024.0))
    newMB = int(newV / (1024.0 * 1024.0))
    if curMB == 0 or curMB != newMB:
        saveIN()
Exemplo n.º 9
0
def OUT(idurl, size):
    """
    Call this when need to count outgoing bandwidth.

    ``size`` - how many bytes sent to user with ``idurl``.
    Typically called when outgoing packet were sent.
    """
    global BandOutDict
    global CountTimeOut
    if not isExistOUT():
        currentFileName = time.strftime('%d%m%y', time.localtime(CountTimeOut))
        if currentFileName != misc.gmtime2str('%d%m%y'):
            saveOUT(currentFileName)
            clear_bandwidthOUT()
            CountTimeOut = time.time()
    currentV = int(BandOutDict.get(idurl, 0))
    newV = currentV + size
    BandOutDict[idurl] = newV
    curMB = int(currentV / (1024.0 * 1024.0))
    newMB = int(newV / (1024.0 * 1024.0))
    if curMB == 0 or curMB != newMB:
        saveOUT()
Exemplo n.º 10
0
def IN(idurl, size):
    """
    Call this when need to count incoming bandwidth.

    ``size`` - how many incoming bytes received from user with ``idurl``.
    Typically called when incoming packet arrives.
    """
    global BandInDict
    global CountTimeIn
    if not isExistIN():
        currentFileName = time.strftime('%d%m%y', time.localtime(CountTimeIn))
        if currentFileName != misc.gmtime2str('%d%m%y'):
            saveIN(currentFileName)
            clear_bandwidthIN()
            CountTimeIn = time.time()
    currentV = int(BandInDict.get(idurl, 0))
    newV = currentV + size
    BandInDict[idurl] = newV
    curMB = int(currentV / (1024.0 * 1024.0))
    newMB = int(newV / (1024.0 * 1024.0))
    if curMB == 0 or curMB != newMB:
        saveIN()