'Movie' 카테고리의 다른 글

빅 히어로(Big Hero 6)  (0) 2016.12.06
프로메테우스(Prometheus)  (0) 2016.12.06
이미테이션게임(The Imitation Game)  (0) 2016.12.06
어카운턴트(The Accountant)  (0) 2016.12.06


'Movie' 카테고리의 다른 글

빅 히어로(Big Hero 6)  (0) 2016.12.06
프로메테우스(Prometheus)  (0) 2016.12.06
뷰티풀 마인드(A Beautiful Mind)  (0) 2016.12.06
어카운턴트(The Accountant)  (0) 2016.12.06


'Movie' 카테고리의 다른 글

빅 히어로(Big Hero 6)  (0) 2016.12.06
프로메테우스(Prometheus)  (0) 2016.12.06
뷰티풀 마인드(A Beautiful Mind)  (0) 2016.12.06
이미테이션게임(The Imitation Game)  (0) 2016.12.06
mail block 여부를 확인해야하는데 telnet 연결을 하면 block이 되더라도 연결은 성공이기 때문에 $? 값이 0 으로 참이다 ㅡㅜ 
($? will contain the exit status of the last command)
그래서 메시지로 확인을 해야하는 경우가 있어 구글링해봄


# exec 3<>/dev/tcp/mx4.naver.com/25

# RESPONSE="`cat <&3`"

# echo "Response is: $RESPONSE"

Response is: 220 mx.naver.com ESMTP uhOoOzccQ6eHbxMheoMwfA - nsmtp

451 4.4.2 Timeout - closing connection uhOoOzccQ6eHbxMheoMwfA - nsmtp


# exec 3<>/dev/tcp/mx4.naver.com/25

# RESPONSE="`cat <&3`"

# echo "Response is: $RESPONSE"

Response is: 421 4.3.2 Your ip blocked from this server O8n3JcaPR-SkE+jwsts6GA - nsmtp 



if [[ "$RESPONS" =~ "blocked" ]]; then

    echo "blocked"

else

    echo "ok"

fi



http://code.activestate.com/recipes/286229-remove-control-character-m-from-opened-html-files/

http://blogger.pe.kr/170

>>> import curses.ascii
>>> ascii.ascii('^V^M')
'\r'
>>> string.replace( str, '\r', '' )


'Python' 카테고리의 다른 글

pidlockfile.py for windows  (0) 2016.12.19
cygwin + ssh + rsync  (0) 2016.12.10
sqlalchemy  (0) 2016.11.28
pexpect.pxssh  (0) 2016.11.24
PEP8  (0) 2016.11.24

sqlalchemy + python-daemon


]# /home/python2.7/bin/pip install SQLAlchemy

]# /home/python2.7/bin/pip install mysql-python

]# mkdir /home/package_manager

]# cd /home/package_manager

]# mkdir bin lib log run

]# cd bin

]# vi package_manager.py


#!/home/python2.7/bin/python

# -*- coding: UTF-8 -*-


import sys

import time

from daemon.runner import DaemonRunner

sys.path.append("/home/package_manager/lib")


class App(object):

    def __init__(self):

        self.stdin_path = "/dev/null"

        self.stdout_path = "/dev/tty"

        self.stderr_path = "/dev/tty"

        self.pidfile_timeout = 0

        self.pidfile_path = "/home/package_manager/run/app.pid"


    def run(self):

        from database import session

        from models import APMDistributionQueue

        while 1:

            tasks = session.query(APMDistributionQueue).all()

            for task in tasks:

                print task.server_info.hostn


            time.sleep(10)


def main():

    DaemonRunner(App()).do_action()


if __name__ == "__main__":

    main() 


]# cd lib

]# vi database.py


 # -*- coding: UTF-8 -*-

from sqlalchemy import create_engine

from sqlalchemy.orm import scoped_session, sessionmaker

from sqlalchemy.ext.declarative import declarative_base


engine = create_engine('mysql+mysqldb://아이디:비밀번호@localhost/manager_new', convert_unicode=True)

Base = declarative_base()

session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))


]# vi models.py


# -*- coding: UTF-8 -*-

from sqlalchemy.sql import func

from sqlalchemy import ForeignKey, Column, Integer, String, DateTime, Table

from sqlalchemy.orm import relationship, backref

from database import Base, engine


class ServerInfo(Base):

       __table__ = Table('info', Base.metadata, autoload=True, autoload_with=engine)


class APMPackage(Base):

    __tablename__ = 'apm_package'

    id = Column(Integer, primary_key=True)

    name = Column(String(100), unique=True)

    packaging_file = Column(String(200))

    unpackaging_path = Column(String(200))

    queue = relationship("APMDistributionQueue", backref=backref('package'), cascade='all, delete, delete-orphan')


    def __init__(self, name, file, path):

        self.name = name

        self.packaging_file = file

        self.unpackaging_path = path


    def __repr__(self):

        return "%s %s %s %s" % (self.id, self.name, self.packaging_file, self.unpackaging_path)


class APMDistributionQueue(Base):

    __tablename__ = 'apm_distribution_queue'

    id = Column(Integer, primary_key=True)

    mode = Column(String(20), nullable=False)

    server_id = Column(Integer, ForeignKey(ServerInfo.idx), nullable=False)

    package_id = Column(Integer, ForeignKey(APMPackage.id), nullable=False)

    status = Column(Integer, default=1, nullable=False)

    reg_date = Column(DateTime(timezone=True), default=func.now(), nullable=False)

    server_info = relationship("ServerInfo", backref=backref('queue'))


    def __init__(self, mode, sid, pid):

        self.mode = mode

        self.server_id = sid

        self.package_id = pid


    def __repr__(self):

        return "%s %s %s %s" % (self.id, self.mode, self.server_id, self.package_id) 


]# cd ../bin

]# package_manager.py start


프로세스가 fork 되면서 sqlalchemy 의 connection pool과의 연결이 끊기는 문제가 발생해서 한참을 고생했다.

해결방법은 run 메소드 안에서 database.py 를 import 하거나 engine 생성시에 pool_recycle 값을 0으로 설정하면 된다.


새로 만든 테이블과 기존에 있던 테이블을 같이 사용하기 위해 declarative_base, automap_base 중 어떤 맵핑클래스를 

사용하는지에따라 구현하는부분이 달라지는데 테스트코드를 만들어봐야 이해할듯하다.


http://programtalk.com/python-examples/daemon.pidfile.PIDLockFile/

 

 


'Python' 카테고리의 다른 글

pidlockfile.py for windows  (0) 2016.12.19
cygwin + ssh + rsync  (0) 2016.12.10
remove ^M(Carriage Return)  (0) 2016.11.30
pexpect.pxssh  (0) 2016.11.24
PEP8  (0) 2016.11.24

http://pexpect.readthedocs.io/en/stable/api/pxssh.html

'Python' 카테고리의 다른 글

pidlockfile.py for windows  (0) 2016.12.19
cygwin + ssh + rsync  (0) 2016.12.10
remove ^M(Carriage Return)  (0) 2016.11.30
sqlalchemy  (0) 2016.11.28
PEP8  (0) 2016.11.24

https://spoqa.github.io/2012/08/03/about-python-coding-convention.html


함수의 시작은 아래와 같이 대응하도록

– get/set

– add/remove

– create/destroy

– start/stop

– insert/delete

– increment/decrement

– old/new

– begin/end

– first/last

– up/down

– min/max

– next/previous

– open/close

– show/hide

– suspend/resume

– parent/child

'Python' 카테고리의 다른 글

pidlockfile.py for windows  (0) 2016.12.19
cygwin + ssh + rsync  (0) 2016.12.10
remove ^M(Carriage Return)  (0) 2016.11.30
sqlalchemy  (0) 2016.11.28
pexpect.pxssh  (0) 2016.11.24

+ Recent posts