db.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # @File : db.py.py
  4. # @Author: becivells
  5. #@Contact : becivells@gmail.com
  6. # @Date : 2018/4/21
  7. #@Software : PyCharm
  8. # @Desc :
  9. import os
  10. from sqlalchemy import Column,VARCHAR
  11. from sqlalchemy.ext.declarative import declarative_base
  12. from config import engine,session_class
  13. from config import repo as configrepo
  14. Base = declarative_base()
  15. class Data(Base):
  16. __tablename__ = 'data'
  17. id = Column(VARCHAR(40),primary_key=True,nullable=False)
  18. name = Column(VARCHAR(30))
  19. path = Column(VARCHAR(100))
  20. ip = Column(VARCHAR(200))
  21. cmd = Column(VARCHAR(100))
  22. user = Column(VARCHAR(30))
  23. interval = Column(VARCHAR(30))
  24. def get_dbconf():
  25. session = session_class()
  26. datas = session.query(Data).all()
  27. session.close()
  28. repo = {}
  29. for data in datas:
  30. if data:
  31. if data.ip:
  32. ip = data.ip.split(',')
  33. else:
  34. ip = ''
  35. repo.update({data.id:{
  36. "name":data.name,
  37. "path":data.path,
  38. "ip":ip,
  39. "cmd":'git pull origin master',
  40. "user":data.user,
  41. 'interval':3
  42. }})
  43. return repo
  44. # def init():
  45. # Base.metadata.create_all(engine)
  46. # print (get_dbconf())