forked from kenshin579/tutorials-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintenance.py
More file actions
executable file
·77 lines (61 loc) · 2.59 KB
/
maintenance.py
File metadata and controls
executable file
·77 lines (61 loc) · 2.59 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os
import shutil
import sys
import tempfile
import urllib.request
from pathlib import Path
################################################################################################
# todo :
################################################################################################
################################################################################################
# Constants
#
################################################################################################
BLOG_MASTER_BRANCH_README_URL = 'https://raw.githubusercontent.com/kenshin579/advenoh.pe.kr/master/README.md'
LOCAL_README_FILE = '../README.md'
################################################################################################
# Functions
#
################################################################################################
def save_file(url, download_folder):
download_filename = 'blog_README.md'
mem = urllib.request.urlopen(url).read()
full_path = os.path.join(download_folder, download_filename)
with open(full_path, mode="wb") as tmp_dir:
tmp_dir.write(mem)
print("saved file")
return full_path
def update_readme():
tmp_dir = tempfile.TemporaryDirectory(dir="/tmp")
print('tmp dir', tmp_dir.name)
remote_file = save_file(BLOG_MASTER_BRANCH_README_URL, tmp_dir.name)
print('remote_file', remote_file)
remote_file_size = Path(remote_file).stat().st_size
local_file_size = Path(LOCAL_README_FILE).stat().st_size
if remote_file_size > local_file_size:
# shutil.copy(remote_file, LOCAL_README_FILE)
with open(remote_file) as f:
lines = f.readlines()
lines[0] = "[](http://hits.dwyl.com/kenshin579/tutorials-java)\n"
with open(LOCAL_README_FILE, "w") as f:
f.writelines(lines)
################################################################################################
# Main function
#
################################################################################################
def main():
parser = argparse.ArgumentParser(description="Maintenance script for tutorials-java")
parser.add_argument("-u", "--update", action='store_true',
help="Update README file from blog branch")
if len(sys.argv[1:]) == 0:
parser.print_help()
parser.exit()
args = parser.parse_args()
print('args', args)
if args.update:
update_readme()
if __name__ == "__main__":
sys.exit(main())