Skip to content

Commit f30000f

Browse files
committed
working with separate index for github
1 parent 7ea5028 commit f30000f

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

Diff for: bin/loadrepo.py

+38-13
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
parser.add_argument("--always", help="always process", default=False, dest='always', action="store_true")
2525
parser.add_argument("--branch", help="git branch (default='%s')" % default_branch, action="store", default=default_branch)
2626
parser.add_argument("--cache", help="location of previously downloaded repo", action="store", default="./cache")
27+
parser.add_argument("--cdnprefix", help="prefix for CDN URLs", action="store", default="")
2728
parser.add_argument("--input", help="YAML of potential repos", action="store", default="data/sources.yaml")
2829
parser.add_argument("--output", help="output directory", action="store", default="./local")
2930
parser.add_argument("--nocleanup", help="do not erase temporary files", default=True, dest='cleanup', action="store_false")
3031
parser.add_argument("--nocopy", help="do not copy files", action="store_false", default=True, dest='copy')
32+
parser.add_argument("--nosparse", help="do not do a sparse checkout", action="store_false", default=True, dest='sparse')
3133
parser.add_argument("--provider", help="only do specific provider", action="store", default="*", dest="provider")
3234
parser.add_argument('repos', help='repos (all if none specified)', metavar='repos', nargs='*')
3335

@@ -88,15 +90,15 @@
8890
if os.path.isdir(gitdir):
8991
os.chdir(gitdir)
9092

91-
cached_commit = sh.git("rev-parse", "HEAD")
93+
cached_commit = sh.git("rev-parse", "HEAD", "--", _err_to_out=True, _out=sys.stdout)
9294

9395
if args.verbose:
9496
sys.stdout.write("INFO: pulling changes from git repo %s\n" % giturl)
95-
sh.git.pull("--ff-only", _err_to_out=True, _out=os.path.join(cachedir, "git-" + repo_handle + ".stdout"))
97+
sh.git.pull("origin", repodata["branch"], _err_to_out=True, _out=sys.stdout)
9698
if args.verbose:
9799
sys.stdout.write("INFO: pull complete\n")
98100

99-
current_commit = sh.git("rev-parse", "HEAD")
101+
current_commit = sh.git("rev-parse", "HEAD", _err_to_out=True, _out=sys.stdout)
100102
if cached_commit == current_commit:
101103
if args.always:
102104
sys.stdout.write("INFO: no changes to repo since last run but processing anyway\n")
@@ -105,17 +107,38 @@
105107
continue
106108
else:
107109
if args.verbose:
108-
sys.stdout.write("INFO: cloning git repo %s\n" % giturl)
109-
sh.git.clone(giturl, gitdir, _err_to_out=True, _out=os.path.join(cachedir, "git-" + repo_handle + ".stdout"))
110-
if args.verbose:
111-
sys.stdout.write("INFO: clone complete\n")
112-
os.chdir(gitdir)
110+
sys.stdout.write("INFO: retrieving git repo %s (sparse=%s)\n" % (giturl, args.sparse))
111+
112+
if args.sparse:
113+
# full clone takes too long
114+
#
115+
os.mkdir(gitdir)
116+
os.chdir(gitdir)
117+
sh.git.init(_err_to_out=True, _out=sys.stdout)
118+
sh.git.remote('add', 'origin', giturl, _err_to_out=True, _out=sys.stdout)
119+
if len(repodata["directory"]) > 0:
120+
sparse_dir = '\\' + repodata["directory"] if repodata["directory"][0] == '!' else repodata["directory"]
121+
sh.git.config('core.sparsecheckout', 'true', _err_to_out=True, _out=sys.stdout)
122+
fsc = open(".git/info/sparse-checkout", "a")
123+
fsc.write("%s/*\n" % sparse_dir)
124+
fsc.close()
125+
sh.git.pull("--depth=1", "origin", repodata["branch"], _err_to_out=True, _out=sys.stdout)
126+
if args.verbose:
127+
sys.stdout.write("INFO: sparse pull complete\n")
128+
else:
129+
sh.git.clone(giturl, gitdir, _err_to_out=True, _out=sys.stdout)
130+
os.chdir(gitdir)
131+
132+
if args.verbose:
133+
sys.stdout.write("INFO: clone complete\n")
113134

114135
if args.verbose:
115136
sys.stdout.write("INFO: switching to branch '%s'\n" % (repodata['branch']))
116-
sh.git.checkout(repodata['branch'], _err_to_out=True, _out=os.path.join(cachedir, "git-" + repo_handle + ".stdout"))
137+
sh.git.checkout(repodata['branch'], _err_to_out=True, _out=sys.stdout)
117138

118-
current_commit = sh.git("rev-parse", "HEAD")
139+
current_commit = sh.git("rev-parse", "HEAD", _err_to_out=True, _out=sys.stdout)
140+
last_mod = "%s" % sh.git.log("-1", "--format=%cd", "--date=iso")
141+
sys.stdout.write("INFO: last modified on %s\n" % last_mod)
119142

120143
logodir = os.path.join(gitdir, repodata['directory'])
121144
if args.verbose:
@@ -183,14 +206,16 @@
183206

184207
if args.verbose:
185208
sys.stdout.write("DEBUG: repo %s copy from '%s' to '%s' (%s)\n" % (repo_handle, str(srcpath), dstpath, shortpath))
209+
210+
imgurl = args.cdnprefix + shortpath
186211
else:
187-
shortpath = "https://raw.githubusercontent.com/" + repodata["repo"] + "/" + repodata["branch"] + srcpath[len(gitdir):]
212+
imgurl = "https://raw.githubusercontent.com/" + repodata["repo"] + "/" + repodata["branch"] + srcpath[len(gitdir):]
188213

189214

190215
images.append({
191216
'name': name,
192217
'src': giturl + "/blob/" + repodata['branch'] + srcpath[len(gitdir):],
193-
'img': shortpath
218+
'img': imgurl
194219
})
195220

196221
sys.stdout.write("OUTPUT: %d svg files found for %s (%s)\n" % (len(images), repo_handle, repodata['repo']))
@@ -204,7 +229,7 @@
204229
data = {
205230
'data': repodata,
206231
'handle': repo_handle,
207-
'lastmodified': datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'),
232+
'lastmodified': last_mod,
208233
'name': repodata['name'] if 'name' in repodata else repo_handle,
209234
'provider': repodata['provider'],
210235
'provider_icon': 'https://www.vectorlogo.zone/logos/' + repodata['provider'] + '/' + repodata['provider'] + '-icon.svg',

Diff for: build-github.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -f "${ENV_FILE}" ]; then
1818
export $(cat "${ENV_FILE}")
1919
fi
2020

21-
OUTPUT_DIR=${OUTPUT_DIR:-./output}
21+
OUTPUT_DIR=${OUTPUT_DIR:-./output-github}
2222
if [ ! -d "${OUTPUT_DIR}" ]; then
2323
echo "INFO: creating output directory ${OUTPUT_DIR}"
2424
mkdir -p "${OUTPUT_DIR}"
@@ -46,6 +46,6 @@ fi
4646
# make the index
4747
#
4848
echo "INFO: building compressed index"
49-
tar cvzf ${BUILD_DIR}/sourceData.tgz ${OUTPUT_DIR}/*/sourceData.json
49+
tar cvzf ${BUILD_DIR}/sourceData-github.tgz ${OUTPUT_DIR}/*/sourceData.json
5050

5151
echo "INFO: completed build at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

Diff for: build.sh renamed to build-gitlab.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ OUTPUT_DIR=${LOCAL_DIR:-./remote}
2525
#
2626
echo "INFO: loading logos into ${OUTPUT_DIR}"
2727
./bin/loadrepo.py \
28-
--output=${OUTPUT_DIR}
28+
--cdnprefix=${CDN_PREFIX} \
29+
--output=${OUTPUT_DIR} \
30+
--provider=gitlab
2931

3032
# to force it to copy even if no new commits, add:
3133
# --always \
3234

35+
BUILD_DIR=${BUILD_DIR:-./build}
36+
if [ ! -d "${BUILD_DIR}" ]; then
37+
echo "INFO: creating build directory ${BUILD_DIR}"
38+
mkdir -p "${BUILD_DIR}"
39+
fi
40+
3341
#
3442
# make the index
3543
#
36-
tar cvzf ${OUTPUT_DIR}/sourceData.tgz ${OUTPUT_DIR}/*/sourceData.json
44+
echo "INFO: building compressed index"
45+
tar cvzf ${BUILD_DIR}/sourceData-gitlab.tgz ${OUTPUT_DIR}/*/sourceData.json
3746

3847
echo "INFO: complete at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

Diff for: data/sources.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
handle: katacontainers
314314
repo: kata-containers/www.katacontainers.io
315315
branch: master
316-
directory: img
316+
directory: static/img
317317
website: 'https://katacontainers.io/'
318318
name: 'Kata Containers'
319319
logo: 'https://www.vectorlogo.zone/logos/katacontainersio/katacontainersio-icon.svg'
@@ -573,7 +573,7 @@
573573
handle: tiagoporto-music
574574
repo: tiagoporto/svg-music-logos
575575
branch: master
576-
directory: src/logos
576+
directory: src/img/logos
577577
website: 'http://tiagoporto.github.io/svg-music-logos/'
578578

579579
- provider: github

0 commit comments

Comments
 (0)