Python GitLab Module Install

pip install python-gitlab

GitLab Login

import gitlab

gl = gitlab.Gitlab('URL', private_token='Token')

Get the list of users

users = gl.users.list()

users = gl.users.list(search='foo')

# by ID
user = gl.users.get(user_id)

# by username
user = gl.users.list(username='root')[0]

Create a user

user = gl.users.create({'email': 'test@hi.com',
                        'password': 'pass',
                        'username': 'test',
                        'name': 'test test'})

Update a user

user.name = 'Real Name'
user.save()

Delete a user

gl.users.delete(user_id)
# or
user.delete()

Block/Unblock a user

user.block()
user.unblock()

Activate/Deactivate a user

user.activate()
user.deactivate()

'IT > Python' 카테고리의 다른 글

Python PowerShell  (0) 2021.01.14
Real-time Python Jenkins Build Status Check  (0) 2021.01.14
Python Url Monitor  (0) 2021.01.13
Python System Info  (0) 2021.01.13
Python Jenkins Module Install  (0) 2021.01.13

Python Url Monitor

import requests
import time
from datetime import datetime


url = ('http://www.interpark.com',)   # tuple
while True:
    for site in url:
        with requests.Session() as s:
            r = s.get(site)
            if r.status_code == 200:          # r.status_code : response status
                print('%s is ok : Response Status : %d' %(site, r.status_code))
                print('%s is ok : site allive' %(site))
            else:
                print('%s is Check : Response Status : %d' % (site, r.status_code))
                print('%s is warrning : site not allive' %(site))

    print(str(datetime.today().time())[:8])
    time.sleep(60)            # 1min loop

'IT > Python' 카테고리의 다른 글

Real-time Python Jenkins Build Status Check  (0) 2021.01.14
Python GitLab Module Install  (0) 2021.01.14
Python System Info  (0) 2021.01.13
Python Jenkins Module Install  (0) 2021.01.13
Python E-Mail Send  (0) 2021.01.13

Python Linux System Info

import os
import time

unumber = os.getuid()
pnumber = os.getpid()
where = os.getcwd()
what = os.uname()
used = os.times()
now = time.time()
means = time.ctime(now)

print ("User number",unumber)
print ("Process ID",pnumber)
print ("Current Directory",where)
print ("System information",what)
print ("System information",used)

print ("\nTime is now",now)
print ("Which interprets as",means)

'IT > Python' 카테고리의 다른 글

Python GitLab Module Install  (0) 2021.01.14
Python Url Monitor  (0) 2021.01.13
Python Jenkins Module Install  (0) 2021.01.13
Python E-Mail Send  (0) 2021.01.13
Python Slack Msg Send  (0) 2021.01.13

Python System Info

Python Jenkins Module Install

pip install python-jenkins

Jenkins Login

server = jenkins.Jenkins('URL', username='ID', password='PASSWD')

Working with Jenkins Jobs

server.create\_job('empty', jenkins.EMPTY\_CONFIG\_XML)  
jobs = server.get\_jobs()

my\_job = server.get\_job\_config('cool-job')

server.build\_job('empty')  
server.disable\_job('empty')  
server.copy\_job('empty', 'empty\_copy')  
server.enable\_job('empty\_copy')  
server.reconfig\_job('empty\_copy', jenkins.RECONFIG\_XML)

server.delete\_job('empty')  
server.delete\_job('empty\_copy')

server.build\_job('api-test', {'param1': 'test value 1', 'param2': 'test value 2'})  
last\_build\_number = server.get\_job\_info('api-test')\['lastCompletedBuild'\]\['number'\]  
build\_info = server.get\_build\_info('api-test', last\_build\_number)

jobs = server.get\_jobs(view\_name='View Name')

'IT > Python' 카테고리의 다른 글

Python Url Monitor  (0) 2021.01.13
Python System Info  (0) 2021.01.13
Python E-Mail Send  (0) 2021.01.13
Python Slack Msg Send  (0) 2021.01.13
python rundeck module install  (0) 2021.01.13

Python E-Mail Send

To_User = 'ToUser@email.com'
From_User = 'SendUser@email.com'
Msg_Subject = 'Subject'
Msg_Description = 'Description'

serverName = 'imail2.targetServerName.com'

msg = MIMEMultipart()

# msg = MIMEText(Msg_Description)       ## 본문
msg['To'] = To_User
msg['From'] = From_User
msg['Subject'] = Msg_Subject      ##제목
msg.attach(MIMEText(Msg_Description))
# msgA.attach(msg)
# msg['Bcc'] = email.utils.formataddr(('Recipient', To_User))  # Recommended for mass emails

path = r'C:\\@@@@.xlsx'
part = MIMEBase("application",'octet-stream')
part.set_payload(open(path,'rb').read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"'% os.path.basename(path))
msg.attach(part)

server = smtplib.SMTP(serverName)
server.sendmail(From_User, To_User, msg.as_string())
server.quit()
print(To_User + ' Email sent successfully')

'IT > Python' 카테고리의 다른 글

Python System Info  (0) 2021.01.13
Python Jenkins Module Install  (0) 2021.01.13
Python Slack Msg Send  (0) 2021.01.13
python rundeck module install  (0) 2021.01.13
Python Jira Module Install  (0) 2021.01.13

Python Slack Msg Send

import requests

def slackSendMsg(botMsg):
    # webhook url
    url = "webhook url"
    payload = {
        "text": botMsg
    }
    requests.post(url, json=payload)

```

'IT > Python' 카테고리의 다른 글

Python Jenkins Module Install  (0) 2021.01.13
Python E-Mail Send  (0) 2021.01.13
python rundeck module install  (0) 2021.01.13
Python Jira Module Install  (0) 2021.01.13
Python Hosts Control  (0) 2021.01.13

+ Recent posts