Python File Searching


import os

import subprocess



def search(dirname):

    try:

        filenames = os.listdir(dirname)

        for filename in filenames:

            full_filename = os.path.join(dirname, filename)

            if os.path.isdir(full_filename):

                search(full_filename)

            else:

                ext = os.path.splitext(full_filename)[-1]

                if ext == '.tar': 

                    # print(full_filename)      ## full name

                    file_pathss = full_filename.rstrip('.tar')  ## 조건

                    print(dirname)      ## dir name

                    # print(subprocess.run(['mkdir', file_pathss], shell=True, check=True))

                    # print(subprocess.run(['tar', 'xvf', full_filename, '-C', file_pathss], shell=True, check=True))

                    # print(subprocess.call(['C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'tar', 'xvf', full_filename, '-C', file_pathss], shell=True, check=True))

    except PermissionError:

        pass



search("c:\\Users\\path\\path\\path")


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

Python package environment settings  (0) 2021.01.14
Get it from Python Parameter Jenkins  (0) 2021.01.14
Python Excel Control  (0) 2021.01.14
Python 개발환경 Setting  (0) 2021.01.14
Python PyAutoGUI Control  (0) 2021.01.14

Python Excel Control

from openpyxl import Workbook
from openpyxl.styles.borders import Border, Side
from openpyxl.styles import PatternFill, Color, Font, Alignment

## 테두리 지정
box = Border(left=Side(border_style="thin", 
            color='FF000000'),
    right=Side(border_style="thin",
            color='FF000000'),
    top=Side(border_style="thin",
            color='FF000000'),
    bottom=Side(border_style="thin",
                color='FF000000'),
    diagonal=Side(border_style="thin",
                color='FF000000'),
    diagonal_direction=0,
    outline=Side(border_style="thin",
                color='FF000000'),
    vertical=Side(border_style="thin",
                color='FF000000'),
    horizontal=Side(border_style="thin",
                color='FF000000')
)

## workbook open
wb = Workbook()
ws = wb.active
ws.title = Site_Target+' Deploy List'
ws['A1'] = 'No.'
ws['B1'] = 'Build Date'
ws['C1'] = 'Commit Date'
ws['D1'] = 'Repo'
ws['E1'] = 'List'
ws['F1'] = 'PMS'
ws['G1'] = 'User'
ws['H1'] = 'Commit Comment'
ws['I1'] = 'Hash No.'
ws['J1'] = 'Reflect No.'
ws['A1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['B1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['C1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['D1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['E1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['F1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['G1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['H1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['I1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws['J1'].fill = PatternFill(patternType='solid', fgColor=Color('EEE8AA'))#색상지정
ws.column_dimensions['A'].width = 4# cell의 가로 사이즈 변경
ws.column_dimensions['B'].width = 12# cell의 가로 사이즈 변경
ws.column_dimensions['C'].width = 19# cell의 가로 사이즈 변경
ws.column_dimensions['D'].width = 22# cell의 가로 사이즈 변경
ws.column_dimensions['E'].width = 100# cell의 가로 사이즈 변경
ws.column_dimensions['F'].width = 16# cell의 가로 사이즈 변경
ws.column_dimensions['G'].width = 18# cell의 가로 사이즈 변경
ws.column_dimensions['H'].width = 55# cell의 가로 사이즈 변경
ws.column_dimensions['I'].width = 43# cell의 가로 사이즈 변경
ws.column_dimensions['J'].width = 12# cell의 가로 사이즈 변경
header_cells = ws['A1':'J1']
for header_row in header_cells:
    for cell in header_row:
            cell.font = Font(name='돋움', size=9, bold=True)
            cell.alignment = Alignment(horizontal='center', vertical='center')
            cell.border = box
header_cells = ws['A':'J']
for header_row in header_cells:
    for cell in header_row:
            cell.font = Font(name='돋움', size=9)
            cell.alignment = Alignment(horizontal='center', vertical='center')
            cell.border = box

## Save
wb.save(Report_dir_M+'/BUILD_'+Site_Target+'_'+nowDate+'.xls')

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

Get it from Python Parameter Jenkins  (0) 2021.01.14
Python File Searching  (0) 2021.01.14
Python 개발환경 Setting  (0) 2021.01.14
Python PyAutoGUI Control  (0) 2021.01.14
Python PowerShell  (0) 2021.01.14

Python 개발환경 Setting

비주얼 스튜디오 코드(Visual Studio Code) 설치

파이썬(Python) 설치

VSCode Extension Setting

  • 비주얼 스튜디오 코드(Visual Studio Code)에 파이썬(Python) 확장(Extension) 설치
  • 1) 메뉴 > 보기 > 확장
  • 2) 검색어에 python 입력
  • 3) Python(Don Jayamanne) 설치

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

Python File Searching  (0) 2021.01.14
Python Excel Control  (0) 2021.01.14
Python PyAutoGUI Control  (0) 2021.01.14
Python PowerShell  (0) 2021.01.14
Real-time Python Jenkins Build Status Check  (0) 2021.01.14

Python PyAutoGUI Control

Python PyAutoGUI install

  • pip install pyautogui

Python PyAutoGUI Keyboard and Mousee Control


import pyautogui



# Move the mouse to the x, y coordinates 100, 150.

pyautogui.moveTo(100, 150) 



# Click the mouse at its current location.

pyautogui.click() 



# Double click the mouse at the

pyautogui.doubleClick() 



# Click the mouse at the x, y coordinates 200, 220.

pyautogui.click(200, 220) 



# Move mouse 10 pixels down, that is, move the mouse relative to its current position.

pyautogui.move(None, 10)  



# Type with quarter-second pause in between each key.

pyautogui.write('Hello world!', interval=0.25)  



# Simulate pressing the Escape key.

pyautogui.press('esc') 

pyautogui.keyDown('shift')

pyautogui.write(['left', 'left', 'left', 'left', 'left', 'left'])

pyautogui.keyUp('shift')

pyautogui.hotkey('ctrl', 'c')

Python PyAutoGUI Display Message Boxes


import pyautogui



pyautogui.alert('This is an alert box.')

pyautogui.confirm('Shall I proceed?')

pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])

pyautogui.prompt('What is your name?')

pyautogui.password('Enter password (text will be hidden)')

Python PyAutoGUI Screenshot Functions


import pyautogui



im1 = pyautogui.screenshot()

im1.save('my_screenshot.png')

im2 = pyautogui.screenshot('my_screenshot2.png')

Python 응용프로그램 실행


import os



## 응용프로그램 실행

os.startfile("C:\path\filename.exe")

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

Python Excel Control  (0) 2021.01.14
Python 개발환경 Setting  (0) 2021.01.14
Python PowerShell  (0) 2021.01.14
Real-time Python Jenkins Build Status Check  (0) 2021.01.14
Python GitLab Module Install  (0) 2021.01.14

Python PowerShell

import subprocess

subprocess.call(["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "ls"])

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

Python 개발환경 Setting  (0) 2021.01.14
Python PyAutoGUI Control  (0) 2021.01.14
Real-time Python Jenkins Build Status Check  (0) 2021.01.14
Python GitLab Module Install  (0) 2021.01.14
Python Url Monitor  (0) 2021.01.13

Real-time Python Jenkins Build Status Check


import jenkins



## Jenkins Info

Jserver = jenkins.Jenkins('url', username='admin', password='admin')



while True:

    lastBuild = Jserver.get_job_info('JobName')['lastBuild']['number']

    url = Jserver.get_build_info('JobName', lastBuild)

    if url['building'] == True:

        print('Jenkins Job Building ...')

        time.sleep(60)

    else:

        if url['result'] == 'SUCCESS':

            print ("Jenkins is success")

            break

        else:

            print ("Jenkins status failed")

            break

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

Python PyAutoGUI Control  (0) 2021.01.14
Python PowerShell  (0) 2021.01.14
Python GitLab Module Install  (0) 2021.01.14
Python Url Monitor  (0) 2021.01.13
Python System Info  (0) 2021.01.13

+ Recent posts