Fix requirements; Update flags; Fix urls in README files;

This commit is contained in:
Maxim Khomutov 2022-04-10 11:59:49 +03:00 committed by SantaSpeen
parent bb67c4e6fd
commit 999ca70916
5 changed files with 29 additions and 18 deletions

View File

@ -1 +0,0 @@
main.py @SantaSpeen

View File

@ -6,7 +6,7 @@
<a href="https://gitflic.ru/user/santaspeen"><img src="https://img.santaspeen.ru/github/magic.svg" alt="magic"></a> <a href="https://gitflic.ru/user/santaspeen"><img src="https://img.santaspeen.ru/github/magic.svg" alt="magic"></a>
</p> </p>
Russian localization: [here](https://gitflic.ru/project/dbi471/git-switch/blob?file=READMEru.md) Русская локализация: [нажать сюда](https://gitflic.ru/project/dbi471/git-switch/blob?file=READMEru.md)
A tool that will help you copy repositories from GitHub into GitFlic. A tool that will help you copy repositories from GitHub into GitFlic.
@ -26,13 +26,23 @@ If you don't have python installed, download it from [http://python.org/](http:/
# Shell # Shell
$ python3 main.py --help $ python3 main.py --help
Usage: main.py [OPTIONS]
Options:
--gf_token TEXT Your GitFlic token. [required]
--gh_token TEXT Your GitHub token. [required]
--clone_folder PATH Directory where to download repositories.
--apply_private Need to copy private repositories?
--apply_organisations Need to copy organisations repositories?
--use_ssh Use SSH mode to upload repositories.
--help Show this message and exit.
``` ```
Then: Then:
* Get GitHub token from: [https://github.com/settings/tokens](https://github.com/settings/tokens) * Get GitHub token from: [https://github.com/settings/tokens](https://github.com/settings/tokens)
* Get GitFlic token from: [https://github.com/settings/tokens](https://gitflic.ru/settings/oauth/token) * Get GitFlic token from: [https://gitflic.ru/settings/oauth/token](https://gitflic.ru/settings/oauth/token)
If you are using 2AF into GitFlic select ssh connection using the key: `--use_ssh true`. If you are using 2AF into GitFlic select ssh connection using the key: `--use_ssh`.
The script will copy all the necessary repositories to `./cloned-repos/<login>/<repo_name>`, then push it to GitFlic The script will copy all the necessary repositories to `./cloned-repos/<login>/<repo_name>`, then push it to GitFlic

View File

@ -30,7 +30,7 @@ $ python3 main.py --help
Изучив аргументы: Изучив аргументы:
* Получите GitHub токен отсюда: [https://github.com/settings/tokens](https://github.com/settings/tokens) * Получите GitHub токен отсюда: [https://github.com/settings/tokens](https://github.com/settings/tokens)
* Получите GitFlic токен отсюда: [https://github.com/settings/tokens](https://gitflic.ru/settings/oauth/token) * Получите GitFlic токен отсюда: [https://gitflic.ru/settings/oauth/token](https://gitflic.ru/settings/oauth/token)
Если у вас подключена 2AF в GitFlic используйте ssh: `--use_ssh true`. Если у вас подключена 2AF в GitFlic используйте ssh: `--use_ssh true`.

27
main.py
View File

@ -7,26 +7,25 @@
Программа была отрефакторена: @SantaSpeen Программа была отрефакторена: @SantaSpeen
""" """
# Типы. Используется для <того, что бы тебя любило IDE>.
from typing import NoReturn, Union
# Удобная и встроенная в Python библиотека логирования. Подробнее: https://docs.python.org/3.10/library/logging.html # Удобная и встроенная в Python библиотека логирования. Подробнее: https://docs.python.org/3.10/library/logging.html
import logging import logging
# Встроенные библиотеки. Нужны для некоторых функций прогрммы. # Встроенные библиотеки. Нужны для некоторых функций прогрммы.
import os import os
import sys import sys
import time import time
# Типы. Используется для <того, что бы тебя любило IDE>.
from typing import NoReturn, Union
# Библиотека для работы с аргументами. Подробнее: https://click.palletsprojects.com/en/8.0.x # Библиотека для работы с аргументами. Подробнее: https://click.palletsprojects.com/en/8.0.x
import click import click
# Библиотека для работы c GitHub API. Подробнее: https://github.com/PyGithub/PyGithub
from github import Github, AuthenticatedUser, PaginatedList
# Библиотека для работы с Gitflic API. Подробнее: https://github.com/SantaSpeen/gitflic
from gitflic import GitflicAuth, Gitflic
# Библиотека для работы с git. Подробнее про систему git: https://habr.com/ru/post/588801/
from git import Repo
# #
import requests import requests
# Библиотека для работы с git. Подробнее про систему git: https://habr.com/ru/post/588801/
from git import Repo
# Библиотека для работы с Gitflic API. Подробнее: https://github.com/SantaSpeen/gitflic
from gitflic import GitflicAuth, Gitflic
# Библиотека для работы c GitHub API. Подробнее: https://github.com/PyGithub/PyGithub
from github import Github, AuthenticatedUser, PaginatedList
# Инициализируем логирование # Инициализируем логирование
log_format = "%(asctime)s - %(name)-5s - %(levelname)-5s - %(message)s" log_format = "%(asctime)s - %(name)-5s - %(levelname)-5s - %(message)s"
@ -181,10 +180,12 @@ class GitSwitch:
@click.command() @click.command()
@click.option("--gf_token", help="Your GitFlic token.", type=str, required=True) @click.option("--gf_token", help="Your GitFlic token.", type=str, required=True)
@click.option("--gh_token", help="Your GitHub token.", type=str, required=True) @click.option("--gh_token", help="Your GitHub token.", type=str, required=True)
@click.option("--apply_private", help="Need to copy private repositories?", default=False, required=False) @click.option("--clone_folder", help="Directory where to download repositories.", default="./cloned-repos",
@click.option("--apply_organisations", help="Need to copy organisations repositories?", default=False, required=False) required=False, type=click.Path())
@click.option("--use_ssh", help="Use SSH mode to upload repositories.", default=False, required=False) @click.option("--apply_private", help="Need to copy private repositories?", default=False, required=False, is_flag=True)
@click.option("--clone_folder", help="Directory where to download repositories.", default="./cloned-repos", required=False) @click.option("--apply_organisations", help="Need to copy organisations repositories?", default=False, required=False,
is_flag=True)
@click.option("--use_ssh", help="Use SSH mode to upload repositories.", default=False, required=False, is_flag=True)
def main(**kwargs): def main(**kwargs):
log.info("New log start.") log.info("New log start.")
log.info(f"Local time: {time.asctime()}") log.info(f"Local time: {time.asctime()}")

View File

@ -2,3 +2,4 @@ click==8.1.1
requests==2.27.1 requests==2.27.1
PyGithub==1.55 PyGithub==1.55
gitflic==1.1 gitflic==1.1
gitpython==3.1.27