Skip to content

Commit

Permalink
Update Version to 3.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmgn committed Apr 1, 2020
1 parent e3c5b90 commit 0d0d804
Show file tree
Hide file tree
Showing 154 changed files with 159 additions and 56,722 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include cup *.py
9 changes: 9 additions & 0 deletions clean_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Arguments:
# None
#
# Returns:
# succ: 0
# fail: not 0
# ##########################################################################
rm -rf ./build ./cup.egg-info ./output ./dist
5 changes: 2 additions & 3 deletions cup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@
from cup import res
from cup.shell import oper
# from cup import oper
from cup import thirdp
from cup import platforms

try:
# pylint: disable=W0104
bidu
__all__ = [
'err', 'net', 'bidu', 'log', 'mail', 'shell', 'time',
'util', 'unittest', 'decorators', 'thirdp', 'platforms'
'util', 'unittest', 'decorators', 'platforms'
]
# pylint:disable=W0702
except:
__all__ = [
'err', 'net', 'log', 'mail', 'shell', 'time',
'util', 'unittest', 'decorators', 'thirdp', 'platforms'
'util', 'unittest', 'decorators', 'platforms'
]

# vi:set tw=0 ts=4 sw=4 nowrap fdm=indent
13 changes: 6 additions & 7 deletions cup/exfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

__all__ = [
'LockFile', 'FILELOCK_SHARED', 'FILELOCK_EXCLUSIVE',
'FILELOCK_NONBLOCKING', 'FILELOCK_UNLOCK', 'mk_newnode'
'FILELOCK_NONBLOCKING', 'FILELOCK_UNLOCK', 'mk_newnode', 'safe_rmtree',
'safe_delete'
]


CANNOT_DEL_PATHLIST = [
'/'
'/',
'/proc',
'/boot',
'/sys'
]


Expand Down Expand Up @@ -73,11 +77,6 @@ def __init__(self, fpath, locktype=FILELOCK_EXCLUSIVE):
self._locktype = locktype
self._fhandle = None
try:
# if FILELOCK_EXCLUSIVE == locktype:
# self._fhandle = os.open(
# self._fpath, os.O_CREAT|os.O_EXCL|os.O_RDWR
# )
# else:
self._fhandle = os.open(
self._fpath, os.O_CREAT | os.O_RDWR
)
Expand Down
3 changes: 2 additions & 1 deletion cup/jenkinslib/internal/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
This module provides some requester to access jenkins.
"""

from cup.thirdp import requests
import requests

from cup.jenkinslib.internal import exception


Expand Down
23 changes: 14 additions & 9 deletions cup/net/asyn/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import cup
from cup import log
from cup import thread
from cup import err as cuperr
from cup.util import misc
from cup.util import threadpool
Expand Down Expand Up @@ -97,7 +98,7 @@ def __init__(self, ip, bindport, thdpool_param):
self._recv_queue = queue.PriorityQueue(0)
self._stopsign = False
self._recv_msg_ind = 0
self._mlock = threading.Lock()
self._rwlock = thread.RWLock()
# _needack_context_queue
# infinite queue TODO: may change it in the future
self._needack_context_queue = queue.Queue()
Expand Down Expand Up @@ -239,18 +240,21 @@ def push_msg2sendqueue(self, msg):
log.info('To create a new context for the sock:{0}'.format(
peer)
)
self._mlock.acquire()
self._rwlock.acquire_readlock()
if peer not in self._peer2context:
self._rwlock.release_readlock()
sock = self.connect(peer)
if sock is not None:
context = sockcontext.CConnContext()
context.set_conn_man(self)
context.set_sock(sock)
context.set_peerinfo(peer)
fileno = sock.fileno()
self._rwlock.acquire_writelock()
self._peer2context[peer] = context
self._fileno2context[fileno] = context
self._context2fileno_peer[context] = (fileno, peer)
self._rwlock.release_writelock()
ret = 0
try:
self._epoll.register(
Expand All @@ -275,7 +279,7 @@ def push_msg2sendqueue(self, msg):
ret = -1
else:
context = self._peer2context[peer]
self._mlock.release()
self._rwlock.release_readlock()
else:
context = self._peer2context[peer]
if ret != 0:
Expand Down Expand Up @@ -321,7 +325,6 @@ def connect(self, peer):
return None

def _handle_new_conn(self, newsock, peer):
self._mlock.acquire()
self._set_sock_params(newsock)
self._set_sock_nonblocking(newsock)
context = sockcontext.CConnContext()
Expand All @@ -331,11 +334,12 @@ def _handle_new_conn(self, newsock, peer):
self._epoll.register(
newsock.fileno(), select.EPOLLIN | select.EPOLLET | select.EPOLLERR
)
self._rwlock.acquire_writelock()
self._fileno2context[newsock.fileno()] = context
self._peer2context[peer] = context
self._context2fileno_peer[context] = (newsock.fileno(), peer)
log.info('a new connection: %s:%s' % (peer[0], peer[1]))
self._mlock.release()
self._rwlock.release_writelock()
log.info('a new connection: {0}'.format(peer))

def cleanup_error_context(self, context):
"""clean up error context"""
Expand All @@ -356,14 +360,15 @@ def _cleanup_context(send_queue, peerinfo):
break
if context is None:
return
self._mlock.acquire()
try:
peerinfo = context.get_peerinfo()
log.info(
'handle socket reset by peer, to close the socket:%s:%s' %
(peerinfo[0], peerinfo[1])
)
self._rwlock.acquire_readlock()
fileno_peer = self._context2fileno_peer[context]
self._rwlock.release_readlock()
try:
sock = context.get_sock()
sock.close()
Expand All @@ -381,14 +386,14 @@ def _cleanup_context(send_queue, peerinfo):
'epoll unregister error:%s, peerinfo:%s' %
(str(error), str(fileno_peer[1]))
)
self._rwlock.acquire_writelock()
del self._fileno2context[fileno_peer[0]]
del self._peer2context[fileno_peer[1]]
del self._context2fileno_peer[context]
self._rwlock.release_writelock()
log.info('socket {0} closed successfully'.format(peerinfo))
except Exception as error:
pass
finally:
self._mlock.release()
# pylint: disable=W0212
self._thdpool.add_1job(_cleanup_context, context._send_queue, peerinfo)
listened_peer = context.get_listened_peer()
Expand Down
60 changes: 59 additions & 1 deletion cup/services/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,34 @@ class CGeneratorMan(object)
"""
import os
import time
import uuid
import random
import string
import socket
import struct
import threading
try:
import Queue as queue
except ImportError:
import queue

import cup
from cup import log
from cup import decorators


__all__ = [
'CGeneratorMan',
'CycleIDGenerator'
'CycleIDGenerator',
'CachedUUID'
]


UUID1 = 0
UUID4 = 1
_UUID_LISTS_FUNCS = [
uuid.uuid1,
uuid.uuid4
]


Expand Down Expand Up @@ -160,4 +175,47 @@ def id2_hexstring(cls, num):
return str_num


@decorators.Singleton
class CachedUUID(object):
"""cached uuid object"""
def __init__(self, mode=UUID1, max_cachenum=100):
"""
ip, port will be encoded into the ID
"""
if mode > len(_UUID_LISTS_FUNCS):
raise ValueError('only support UUID1 UUID4')
self._uuidgen = _UUID_LISTS_FUNCS[mode]
self._fifoque = queue.Queue(max_cachenum)
self._max_cachenum = max_cachenum

def get_uuid(self, num=1):
"""
get serveral uuids by 'num'
:return:
a list of uuids (in hex string)
"""
ret = []
while num > 0:
try:
item = self._fifoque.get(block=False)
ret.append(item)
num -= 1
except queue.Empty:
self.gen_cached_uuid()
return ret

def gen_cached_uuid(self, num=50):
"""
generate num of uuid into cached queue
"""
while num > 0:
try:
self._fifoque.put(self._uuidgen().hex, block=False)
num -= 1
except queue.Full:
break
size = self._fifoque.qsize()
log.info('after generate cached uuid queue size :{0}'.format(size))

# vi:set tw=0 ts=4 sw=4 nowrap fdm=indent
2 changes: 1 addition & 1 deletion cup/services/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _do_open4read(self, start_logid=-1):
return True
# pylint:disable=W0703
# need such an exception
except Exception as err:
except OSError as err:
log.error('failed to open log stream :{0}'.format(err))
return False

Expand Down
2 changes: 1 addition & 1 deletion cup/shell/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import cup
from cup import log
from cup.thirdp import pexpect
import pexpect


__all__ = [
Expand Down
84 changes: 0 additions & 84 deletions cup/thirdp/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions cup/thirdp/mysql.py

This file was deleted.

Loading

0 comments on commit 0d0d804

Please sign in to comment.