-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitHubUploader.py
83 lines (72 loc) · 3.1 KB
/
GitHubUploader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python3
#!python3
#encoding:utf-8
import sys
import os.path
import subprocess
import configparser
import argparse
import web.service.github.api.v3.AuthenticationsCreator
import web.service.github.api.v3.Client
import database.src.Database
import cui.uploader.Main
import web.log.Log
import database.src.contributions.Main
import setting.Setting
import threading
class Main:
def __init__(self):
pass
def Run(self):
parser = argparse.ArgumentParser(
description='GitHub Repository Uploader.',
)
parser.add_argument('path_dir_pj')
parser.add_argument('-u', '--username')
parser.add_argument('-d', '--description')
parser.add_argument('-l', '--homepage', '--link', '--url')
parser.add_argument('-m', '--messages', action='append')
args = parser.parse_args()
# print(args)
# print('path_dir_pj: {0}'.format(args.path_dir_pj))
# print('-u: {0}'.format(args.username))
# print('-d: {0}'.format(args.description))
# print('-l: {0}'.format(args.homepage))
self.__setting = setting.Setting.Setting(os.path.abspath(os.path.dirname(__file__)))
path_dir_db = self.__setting.DbPath
web.log.Log.Log().Logger.debug(path_dir_db)
# os.path.basename()で空文字を返されないための対策
# https://docs.python.jp/3/library/os.path.html#os.path.basename
if args.path_dir_pj.endswith('/'):
args.path_dir_pj = args.path_dir_pj[:-1]
if None is args.username:
print(self.__setting.GithubUsername)
args.username = self.__setting.GithubUsername
self.__db = database.src.Database.Database(os.path.abspath(os.path.dirname(__file__)))
self.__db.Initialize()
if None is self.__db.Accounts['Accounts'].find_one(Username=args.username):
web.log.Log.Log().Logger.warning('指定したユーザ {0} はDBに存在しません。GitHubUserRegister.pyで登録してください。'.format(args.username))
return
# Contributionsバックアップ
usernames = []
for a in self.__db.Accounts['Accounts'].find(): usernames.append(a['Username'])
th = ContributionsThread(path_dir_db, self.__db, usernames)
th.start()
# アップローダ起動
creator = web.service.github.api.v3.AuthenticationsCreator.AuthenticationsCreator(self.__db, args.username)
authentications = creator.Create()
client = web.service.github.api.v3.Client.Client(self.__db, authentications, args)
main = cui.uploader.Main.Main(self.__db, client, args)
main.Run()
class ContributionsThread(threading.Thread):
def __init__(self, path_dir_db, db, usernames):
threading.Thread.__init__(self)
self.__path_dir_db = path_dir_db
self.__db = db
self.__usernames = usernames
def run(self):
m = database.src.contributions.Main.Main(self.__path_dir_db)
for username in self.__usernames: m.Run(username)
if __name__ == '__main__':
main = Main()
main.Run()