Skip to content

Commit

Permalink
Update cup to lastest 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmgn committed Jul 3, 2016
1 parent 5765ac0 commit 8dd8657
Show file tree
Hide file tree
Showing 20 changed files with 680 additions and 428 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

# matach all python pyc files
*.pyc
<<<<<<< HEAD
.svn
=======
>>>>>>> origin/master
cup/bidu
14 changes: 0 additions & 14 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
<<<<<<< HEAD
Version: 1.4.1.0
- Under development:
* autosleep
* hdfs/ftp operation
* unittest assert_log_regex assert_regex

- cup.bidu
* [Bug] sms cannot handle \n as line separator
- cup.log
* [Enhancement] change check existence of logfile to try - except.

=======
Version: 1.4.2.0
* [Bug] oper.is_proc_exist. fix a bug while check proc exist
* [New] Add cup.services.executor. Exec and delay_exec service
Expand All @@ -34,7 +21,6 @@ Version: 1.4.1.0 - [not existent on github.com]
* [Bug] cup.util.conf - A sort method bug
* [Bug] sms cannot handle \n as line separator

>>>>>>> origin/master
Version: 1.2.0
- unittest
* [New] Add assert_not_eq
Expand Down
6 changes: 0 additions & 6 deletions cup/.gitignore

This file was deleted.

13 changes: 10 additions & 3 deletions cup/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
Version: 1.5.1
Version: 1.5.3 - Starting from 2016.6 to XXX
* [New] cup.util.conf - support $include "conf_file" syntax [write/read]
* [Enhancement] cup.net.async - enhance network write/read speed
* [Improvement] - Improve cup.log performance

Version: 1.5.1 && 1.5.2
* [New] cup.log - add xxx_if
* [New] cup.thirdp - replace MySQLdb with pymysql.
Use can still use "from cup.thirdp import MySQLdb"
* [Bug] HdfsXmlConf bug. Configure2Dict disorder bug
* from cup.thirdp import pymysql
* import MySQLdb
* [New] cup.util.generator - get_random_str
* [Bug] cup.util.conf - bug fix

Version: 1.5.0
* [New] cup.jenkinslib - add jenkins lib with which you can operate on jenkins jobs
Expand Down
164 changes: 86 additions & 78 deletions cup/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
G_INITED_LOGGER = []


# pylint:disable=C0103
info = logging.info
warn = logging.warn
error = logging.error
debug = logging.debug
critical = logging.critical


class _Singleton(object): # pylint: disable=R0903
"""
Singleton你的类.
Expand Down Expand Up @@ -118,6 +126,7 @@ def _setlogger(self, logger):
def _reset_logger(self, logger):
del self._pylogger
self._pylogger = logger
logging.root = logger

def is_initalized(self):
"""
Expand Down Expand Up @@ -146,7 +155,8 @@ def _config_filelogger(
self._maxsize = maxsize
# '%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(message)s'
formatter = logging.Formatter(
'%(levelname)s: %(asctime)s %(message)s'
'%(levelname)s: %(asctime)s * '
'[%(process)d:%(thread)d] [%(filename)s:%(lineno)s] %(message)s'
)
if bprint_console:
streamhandler = logging.StreamHandler()
Expand Down Expand Up @@ -254,7 +264,8 @@ def init_comlog(
"""
loggerman = _LoggerMan()
if loggerman.is_initalized() is False:
loggerman._setlogger(logging.getLogger(loggername))
# loggerman._setlogger(logging.getLogger(loggername))
loggerman._setlogger(logging.getLogger())
if os.path.exists(logfile) is False:
if platforms.is_linux():
os.mknod(logfile)
Expand Down Expand Up @@ -329,78 +340,78 @@ def _fail_handle(msg, e):
print '%s\nerror:%s' % (msg, e)


def info(msg, back_trace_len=0):
"""
logging.INFO的日志打印
"""
try:
msg = _log_file_func_info(msg, back_trace_len)
loggerman = _LoggerMan()
loggerman._getlogger().info(msg)
except err.LoggerException:
return
except Exception as e:
_fail_handle(msg, e)


def debug(msg, back_trace_len=0):
"""
:param msg:
logging.DEBUG级别的日志打印。
:param back_trace_len:
为扩展预留的参数, 正常使用可忽略。
"""
try:
msg = _log_file_func_info(msg, back_trace_len)
loggerman = _LoggerMan()
loggerman._getlogger().debug(msg)
except err.LoggerException:
return
except Exception as e:
_fail_handle(msg, e)


def warn(msg, back_trace_len=0):
"""
logging.WARN级别的日志打印
"""
try:
msg = _log_file_func_info(msg, back_trace_len)
loggerman = _LoggerMan()
loggerman._getlogger().warn(msg)
except err.LoggerException:
return
except Exception as e:
_fail_handle(msg, e)


def error(msg, back_trace_len=0):
"""
logging.ERROR级别的日志打印
"""
try:
msg = _log_file_func_info(msg, back_trace_len)
loggerman = _LoggerMan()
loggerman._getlogger().error(msg)
except err.LoggerException:
return
except Exception as error:
_fail_handle(msg, error)


def critical(msg, back_trace_len=0):
"""
logging.CRITICAL级别的日志打印
"""
try:
msg = _log_file_func_info(msg, back_trace_len)
loggerman = _LoggerMan()
loggerman._getlogger().critical(msg)
except err.LoggerException:
return
except Exception as e:
_fail_handle(msg, e)
# def info(msg, back_trace_len=0):
# """
# logging.INFO的日志打印
# """
# try:
# msg = _log_file_func_info(msg, back_trace_len)
# loggerman = _LoggerMan()
# loggerman._getlogger().info(msg)
# except err.LoggerException:
# return
# except Exception as e:
# _fail_handle(msg, e)
#
#
# def debug(msg, back_trace_len=0):
# """
# :param msg:
# logging.DEBUG级别的日志打印。
# :param back_trace_len:
# 为扩展预留的参数, 正常使用可忽略。
#
# """
# try:
# msg = _log_file_func_info(msg, back_trace_len)
# loggerman = _LoggerMan()
# loggerman._getlogger().debug(msg)
# except err.LoggerException:
# return
# except Exception as e:
# _fail_handle(msg, e)
#
#
# def warn(msg, back_trace_len=0):
# """
# logging.WARN级别的日志打印
# """
# try:
# msg = _log_file_func_info(msg, back_trace_len)
# loggerman = _LoggerMan()
# loggerman._getlogger().warn(msg)
# except err.LoggerException:
# return
# except Exception as e:
# _fail_handle(msg, e)
#
#
# def error(msg, back_trace_len=0):
# """
# logging.ERROR级别的日志打印
# """
# try:
# msg = _log_file_func_info(msg, back_trace_len)
# loggerman = _LoggerMan()
# loggerman._getlogger().error(msg)
# except err.LoggerException:
# return
# except Exception as error:
# _fail_handle(msg, error)
#
#
# def critical(msg, back_trace_len=0):
# """
# logging.CRITICAL级别的日志打印
# """
# try:
# msg = _log_file_func_info(msg, back_trace_len)
# loggerman = _LoggerMan()
# loggerman._getlogger().critical(msg)
# except err.LoggerException:
# return
# except Exception as e:
# _fail_handle(msg, e)


def setloglevel(logginglevel):
Expand Down Expand Up @@ -494,14 +505,11 @@ def debug_if(bol, msg, back_trace_len=1):
)
cup.log.info('test info')
cup.log.debug('test debug')
cup.log.debug('中文')
cup.log.info('中文'.decode('utf8'))
cup.log.reinit_comlog(
're-test', cup.log.DEBUG, './re.test.log',
cup.log.ROTATION, 102400000, False
)
cup.log.info('re:test info')
cup.log.debug('re:test debug')
cup.log.debug('re:中文')
cup.log.reinit_comlog(
're-test', cup.log.DEBUG, './re.test.log',
cup.log.ROTATION, 102400000, False
Expand Down
2 changes: 1 addition & 1 deletion cup/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SmtpMailer(object): # pylint: disable=R0903
_COMMA_SPLITTER = ','

def __init__(
self, sender, server='mail2-in.baidu.com', port=25, is_html=False
self, sender, server, port=25, is_html=False
):
"""
"""
Expand Down
9 changes: 4 additions & 5 deletions cup/net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ def set_sock_reusable(sock, resuable=True):
"""
设置socket的端口是否可被重复使用, 默认resuable==True
"""
value = 0
if resuable:
value = 1
else:
value = 0
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, value)


def set_sock_linger(sock):
def set_sock_linger(sock, l_onoff=1, l_linger=0):
"""
关闭socket的linger参数。
实际产生的效果如下:
Expand All @@ -150,8 +149,8 @@ def set_sock_linger(sock):
struct.pack('ii', 0, 0)
)
"""
l_onoff = 0
l_linger = 0
# l_onoff = 1
# l_linger = 0
sock.setsockopt(
socket.SOL_SOCKET, socket.SO_LINGER, struct.pack(
'ii', l_onoff, l_linger
Expand Down
29 changes: 24 additions & 5 deletions cup/net/async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,34 @@
:last_date:
2014
:descrition:
**Async Module是ython tcp异步通讯框架.**
**Async Module是python tcp异步消息框架.**
"""

# TODO:
# 1. If the socket has been in a state in which it does not send or
# recv any msg for more than 30mins. Shutdown the context.
# TODO:
# 2. If the socket has too many msg pending there.
# 1. If the socket has been in a state in which it does not send or
# recv any msg for more than 30mins. Shutdown the context.
# 2. Msg management


# Enhancement list:
# 1. If the socket has too many msg pending there.
# and msg cannot be sent out. Consider this net link as dead.
# and shutdown && close it
# 2. Multiple threads sending things.


# BUGS:
# FIXED:
# 1. Send socket does not register in epoll
# 2. Peer2Context has resource competition
# 3. connection has starvation bug


# Silly mistakes that I made:
# 1. TCP context creation and deletion does not has lock. (Mainly on creation)
# 2. Net MSG queue will become very large if the network read/write speed does
# not match.
# 3.


# vi:set tw=0 ts=4 sw=4 nowrap fdm=indent
Loading

0 comments on commit 8dd8657

Please sign in to comment.