-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_projects.py
102 lines (79 loc) · 2.71 KB
/
create_projects.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import sys
import urllib3
urllib3.disable_warnings()
GITHUB_KEY=""
USERNAME=""
PASSWORD=""
def get_org_repos():
from github import Github
g = Github(GITHUB_KEY)
orgs_list = ['riscv', 'ucb-bar', 'sifive', 'lowRISC']
org_repos = []
for org in orgs_list:
print "Fetching repos for %s" % org
for repo in g.get_user(org).get_repos():
print "\tGet repo: %s" % repo.full_name
org_repos.append( (org, repo.name) )
return org_repos
def create_projects(org_repos):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from pprint import pprint
import time
import requests
driver = webdriver.Firefox()
driver.get("https://git.oschina.net/login")
driver.find_element_by_id("user_login").send_keys(USERNAME)
driver.find_element_by_id("user_password").send_keys(PASSWORD)
driver.find_element_by_id("new_user").submit()
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "followers-number"))
)
except Exception, e:
print "Failed at login", e
sys.exit(-1)
for org_repo in org_repos:
org, repo = org_repo
print "Check whether the project [%s/%s] existed:" % (org, repo)
r = requests.get("https://git.oschina.net/cnrv-%s/%s" % (org, repo))
if r.status_code != 404:
print "Yes"
continue
else:
print "No"
print "Start Create Project: %s/%s on git.oschina.net" % (org, repo)
try:
driver.get("https://git.oschina.net/projects/new")
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "git-footer-main"))
)
except Exception, e:
print "Failed at repo: %s [%s]" % (org_repo, e)
sys.exit(-1)
driver.find_element_by_xpath('//div[text()="cnrv-riscv"]').click()
time.sleep(1)
driver.find_element_by_xpath('//div[text()="cnrv-%s"]' % org).click()
time.sleep(1)
# driver.find_element_by_id("import-link").click()
# driver.find_element_by_id("project_import_url").clear()
# driver.find_element_by_id("project_import_url").send_keys("https://github.com/%s/%s" % (org, repo))
driver.find_element_by_id("project_name").clear()
driver.find_element_by_id("project_name").send_keys(repo)
time.sleep(1)
driver.find_element_by_id("project_path").clear()
driver.find_element_by_id("project_path").send_keys(repo)
time.sleep(1)
driver.find_element_by_id("readme").click()
driver.find_element_by_id("new_project").submit()
print "Wait 3s"
time.sleep(3)
def main():
org_repos = get_org_repos()
create_projects(org_repos)
if __name__ == "__main__":
main()