-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·191 lines (167 loc) · 5.4 KB
/
build.sh
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# in here all the tools for this project is automatazied
# this script manages this project by building pydocs, uploading to pypi
# and compiling the source running tests pushing to launchpad and more
# set python version
PY=python3
# get version of package
# combine with name to get filenames
V="$($PY setup.py -V)" # get version
TO="release" # get release dir
NAME="hashit-${V}" # set combined name
ZIP="dist/${NAME}.zip" # set zip output
TAR="dist/${NAME}.tar.gz" # se tarball output
COM=("build" "clean" "docs" "push" "test" "install" "upload") # array of commands
# for if statment
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
if [ "$1" == "docs" ]
then
# build docs using pydoc
$PY -m pydoc -w hashit
$PY -m pydoc -w hashit.__main__
$PY -m pydoc -w hashit.detection
$PY -m pydoc -w hashit.extra
$PY -m pydoc -w hashit.version
mv -f *.html ./docs/pydocs
#cd ./docs/pydocs
#find . -name "*.ht*" | while read i; do pandoc -f html -t markdown "$i" -o "${i%.*}.md"; done
#cd ../..
# clean/create file
echo -e "---\nlayout: default\n---\n" > ./docs/pydoc.md
$PY -c "from pydocmd.__main__ import main; import sys; sys.argv = ['', 'simple', 'hashit+', 'hashit.__main__+', 'hashit.detection+', 'hashit.extra+']; main()" >> ./docs/pydoc.md
printf "\n\n[back](index.md)" >> ./docs/pydoc.md # add back button
# push new documentation to wiki
sudo cp ./docs/*.md ../hashit.wiki
sudo mv ../hashit.wiki/index.md ../hashit.wiki/Home.md
cd ../hashit.wiki
# remove layout
sudo chmod 777 *.md
sudo sed -i '/layout: default/d' *.md
sudo sed -i '/---/d' *.md
sudo sed -e 's/\.md//g' -i *.md
# push to git
sudo git add .
sudo git commit -m "Updated wiki"
exit
fi
if [ "$1" == "push" ]
then
echo "push hashit to origin (github) and launchpad (ppa)"
git push origin master
git push launchpad master
cd ../hashit.wiki
echo "PUSH wiki"
sudo git push
exit
fi
if [ "$1" == "install" ]
then
$PY setup.py install
rm -rf ./dist
exit
fi
if [ "$1" == "test" ]
then
python3 setup.py test
python setup.py test
rm */*.pyc # remove .pyc files from python2
# and exit
exit
fi
if [ "$1" == "clean" ]
then
if [ -d "hashit.egg-info" ]
then
rm -rf "hashit.egg-info"
echo "Removed egg-info"
fi
if [ -d "dist" ]
then
rm -rf "dist"
echo "Removed dist"
fi
if [ -d "build" ]
then
rm -rf "build"
echo "Removed build"
fi
if [ -d "release/deb_dist" ]
then
rm -rf "release/deb_dist"
echo "Removed deb_dist"
fi
if [ -d "_build" ]
then
rm -rf "_build"
echo "Removed _build"
fi
# clean debian dir
cd debian
if [ -d "hashit" ]; then rm -rf "hashit"; echo "Removed debian/hashit/*"; fi
if [ -f "debhelper-build-stamp" ]; then rm -rf "debhelper-build-stamp"; echo "Removed debian/debhelper-build-stamp"; fi
if [ -f "files" ]; then rm -rf "files"; echo "Removed debian/files"; fi
if [ -f "hashit.debhelper.log" ]; then rm -rf "hashit.debhelper.log"; echo "Removed debian/hashit.debhelper.log"; fi
if [ -f "hashit.postinst.debhelper" ]; then rm -rf "hashit.postinst.debhelper"; echo "Removed debian/hashit.postinst.debhelper"; fi
if [ -f "hashit.prerm.debhelper" ]; then rm -rf "hashit.prerm.debhelper"; echo "Removed debian/hashit.prerm.debhelper"; fi
if [ -f "hashit.substvars" ]; then rm -rf "hashit.substvars"; echo "Removed debian/hashit.substvars"; fi
cd ..
# delete pycache
find . -name "__pycache__" -exec rm -rf {} +
rm -rf */*.pyc
exit
fi
if [ "$1" == "upload" ]
then
$PY setup.py sdist upload
rm -rf ./dist
exit
fi
if [ "$1" == "build" ]
then
# Move and print messages
SILENT="$($PY setup.py sdist --quiet --formats zip,gztar)"
echo "Version, $V at $ZIP and $TAR"
mv $ZIP "${TO}/hashit.zip"
mv $TAR "${TO}/hashit.tar.gz"
echo "Moved to ${TO}/hashit.zip and ${TO}/hashit.tar.gz"
rm -r dist/
# copy changelog to debian
cp "./changelog" "debian/"
read -p "Push to launchpad (y/n)? " choice
case "$choice" in
# for launchpad dailybuilds
# add remote and force push deb package
y|Y ) git remote add launchpad git+ssh://javadsm@git.launchpad.net/python3-hashit; git push --force --set-upstream launchpad master;;
n|N ) :;;
* ) :;;
esac
read -p "Build locally (y/n)? " choice
case "$choice" in
# build locally on your machine
y|Y ) rm ./release/*.deb; debuild -b -uc -us; mv ../*.deb ./release/; rm ../hashit_*;;
n|N ) :;;
* ) :;;
esac
# exit
exit
fi
containsElement "$1" ${COM[@]}
# check for element
if [ $? ]
then
echo -e "No arguments selected, use one of the following:\n"
echo " build - builds python, to either deb or source dist (can upload to launchpad)"
echo " clean - removed extra folders and files from either build or python (*.pyc and __pycache__)"
echo " docs - builds docs (markdown and html) and updates wiki (commits)"
echo " push - pushes to both github and launchpad (such does build)"
echo " test - runs unittests"
echo " help (anything really) - prints this messages and exits"
echo " install - installs used pip/setuptools"
echo -e " upload - upload to pypi\n"
exit
fi