forked from LHEEA/meshmagick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_doc.py
executable file
·160 lines (118 loc) · 3.26 KB
/
deploy_doc.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from git import Repo
from subprocess import call
import os
from distutils.dir_util import copy_tree, remove_tree
from tempfile import mkdtemp
import sys
def checkout_branch(repo, branch):
# TODO: faire le check que la branche demandee existe bien dans le repo
print(("\nChecking out to branch %s" % branch))
try:
print((repo.git.checkout(branch)))
except:
raise RuntimeError('Unable to checkout to branch %s' % branch)
def stash_modifs(repo):
print("\nStash local modifications")
print("-------------------------\n")
try:
print((repo.git.stash(all=True)))
except:
raise RuntimeError('Unable to stash modifications')
def unstash_modifs(repo):
print("\nUnstash local modifications")
print("---------------------------\n")
try:
print((repo.git.stash('pop', 'stash@{0}')))
except:
raise RuntimeError('Unable to unstash modifications')
def sphinx_build(working_dir):
print(working_dir)
def empty_dir():
pass
def copy_temp():
return 'path'
def retrieve_copy_temp():
pass
def commit(repo, msg):
pass
def push_github(repo, remote):
pass
def get_current_branch(repo):
branches = repo.git.branch()
for branch in branches.split('\n'):
if branch.startswith('*'):
cur_branch = branch[2:]
break
return cur_branch
if __name__ == '__main__':
print("\n========================================")
print("Deploying Sphinx documentation on GitHub")
print("========================================")
repo = Repo()
working_dir = repo.working_tree_dir
# Getting the current branch
cur_branch = get_current_branch(repo)
stash_modifs(repo)
try:
# Checking out the master branch
# TODO: devrait pourvoir etre mis en parametre de la ligne de commande
checkout_branch(repo, 'master')
# Building sphinx documentation
sphinx_build(working_dir)
except:
print("Failed, getting back to initial state")
checkout_branch(repo, cur_branch)
unstash_modifs(repo)
checkout_branch(repo, cur_branch)
unstash_modifs(repo)
# repo = Repo()
# git = repo.git
#
# branches = git.branch()
# print branches
#
# branches.split()
#
# # Getting the current branch (better way to do that ?)
# for branch in branches.split('\n'):
# if branch.startswith('*'):
# cur_branch = branch[2:]
#
#
# # Checking out to master branch
# git.checkout('master')
#
# # Going to doc dir and building documentation
# chdir('doc')
# system('make clean')
# system('make html')
#
# # Copying html files into a tempdir
# tempdir = mkdtemp()
# print tempdir
#
# # TODO: aller cherche dans le conf.py le dossier build (.build ou _build)
# html_files = os.path.join(getcwd(), '.build/html')
#
#
# copy_tree(html_files, tempdir)
# chdir('..')
#
#
# git.checkout('gh-pages')
#
# # Removing everything here
# system('rm -rf ./*') # TODO: remplacer par des fonctions pures python
#
# copy_tree(tempdir, '.')
#
# git.commit(m='Updating documentation', a=True)
#
#
# # Checking out back to the current branch
# git.checkout(cur_branch)
#
#
# print git.branch()