python-gitlabのサンプルコード

/ python

python-gitlab documentationを踏まえて動くサンプルコードを掲載する。

https://python-gitlab.readthedocs.io/en/stable/index.html

install / import

インストール

pip install --upgrade python-gitlab

インポートと初期化

import gitlab
gl = gitlab.Gitlab('https://gitlab.arm.com')

list projects

for project in gl.projects.list():
    print(f'* {project.name} [{project.http_url_to_repo}]({project.http_url_to_repo})')

結果

list groups

for group in gl.groups.list():
    print(f'* {group.name} [{group.web_url}]({group.web_url})')

結果

list projects in group

group = gl.groups.get('SystemReady')
for project in group.projects.list():
    project = gl.projects.get(project.id) # need if lists branches, tree and so on.
    print(f'* {project.name} [{project.http_url_to_repo}]({project.http_url_to_repo})')

結果

list files in project

project = gl.projects.get('systemready/linuxboot-resources')
for item in project.repository_tree(ref='master', recursive=True, all=True):
    print(f"* {item['path']} ({item['type']}) {item['mode']}")

結果

  • FVP (tree) 040000
  • RPi4 (tree) 040000
  • RPi4/Code (tree) 040000
  • RPi4/DemoMedia (tree) 040000
  • RPi4/DemoMedia/Images (tree) 040000
  • SBSA-QEMU (tree) 040000
  • SBSA-QEMU/Code (tree) 040000
  • SBSA-QEMU/Code/scripts (tree) 040000
  • SBSA-QEMU/DemoMedia (tree) 040000
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo (tree) 040000
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell (tree) 040000
  • FVP/README.md (blob) 100644
  • README.md (blob) 100644
  • RPi4/Code/0001-Platform-RaspberryPi-RPi4-Added-LinuxBoot.patch (blob) 100644
  • RPi4/Code/0001-adding-Basic-LinuxBoot-defconfig.patch (blob) 100644
  • RPi4/DemoMedia/Images/BootManager.png (blob) 100644
  • RPi4/DemoMedia/Images/BootUEFI.png (blob) 100644
  • RPi4/DemoMedia/Images/FedoraACPI.png (blob) 100644
  • RPi4/DemoMedia/Images/FedoraEFIVars.png (blob) 100644
  • RPi4/DemoMedia/Images/FedoraLogin.png (blob) 100644
  • RPi4/DemoMedia/Images/FedoraOSInfo.png (blob) 100644
  • RPi4/DemoMedia/Images/LinuxBootBootManager1.png (blob) 100644
  • RPi4/DemoMedia/Images/LinuxBootBootManager2.png (blob) 100644
  • RPi4/DemoMedia/Images/UEFIShell.png (blob) 100644
  • RPi4/DemoMedia/Images/WelcomeToFedora.png (blob) 100644
  • RPi4/DemoMedia/Images/kexec.png (blob) 100644
  • RPi4/DemoMedia/Images/u-root.png (blob) 100644
  • RPi4/DemoMedia/RPi4fedora.mov (blob) 100644
  • RPi4/README.md (blob) 100644
  • SBSA-QEMU/Code/bootMgr.patch (blob) 100644
  • SBSA-QEMU/Code/linuxboot.patch (blob) 100644
  • SBSA-QEMU/Code/linuxboot_defconfig (blob) 100644
  • SBSA-QEMU/Code/scripts/Edk2Buildscript.sh (blob) 100644
  • SBSA-QEMU/Code/scripts/Edk2Rebuildscript.sh (blob) 100644
  • SBSA-QEMU/Code/scripts/ImageBuildscript.sh (blob) 100755
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo/EmulatorStarting.PNG (blob) 100644
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo/automaticRun.webm (blob) 100644
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo/bootedToACS.PNG (blob) 100644
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo/kexecACSKernel.PNG (blob) 100644
  • SBSA-QEMU/DemoMedia/PlatformBootMgrDemo/urootUnitAutomaticallyRunACSKernel.PNG (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/LBKernel1.png (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/LBKernel2.png (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/LinuxbootOnSbsaqemuDemo.webm (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/Stage2Os.png (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/StartingEmulator.png (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/UEFImenu.png (blob) 100644
  • SBSA-QEMU/DemoMedia/ReplaceUefiShell/UEFImenu2.png (blob) 100644
  • SBSA-QEMU/README.md (blob) 100644
  • SBSA-QEMU/longGuide.md (blob) 100644

get file content

project = gl.projects.get('systemready/linuxboot-resources')
text = project.files.raw('README.md', ref='master').decode('utf-8', errors='ignore')