Skip to content

Commit 7ea5028

Browse files
committed
build github only w/hotlinks
1 parent 1dc275f commit 7ea5028

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

bin/loadrepo.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
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")
2727
parser.add_argument("--input", help="YAML of potential repos", action="store", default="data/sources.yaml")
28-
parser.add_argument("--output", help="output directory", action="store", default="./logos")
28+
parser.add_argument("--output", help="output directory", action="store", default="./local")
2929
parser.add_argument("--nocleanup", help="do not erase temporary files", default=True, dest='cleanup', action="store_false")
30+
parser.add_argument("--nocopy", help="do not copy files", action="store_false", default=True, dest='copy')
31+
parser.add_argument("--provider", help="only do specific provider", action="store", default="*", dest="provider")
3032
parser.add_argument('repos', help='repos (all if none specified)', metavar='repos', nargs='*')
3133

3234
args = parser.parse_args()
@@ -65,6 +67,10 @@
6567

6668
repodata = repolist[repo_handle]
6769

70+
if args.provider != '*' and args.provider != repodata['provider']:
71+
sys.stdout.write("INFO: skipping %s (provider is %s, not %s)\n" % (repo_handle, repodata['provider'], args.provider))
72+
continue
73+
6874
sys.stdout.write("OUTPUT: processing %s (%s)\n" % (repo_handle, repodata["repo"]))
6975

7076
gitdir = os.path.join(cachedir, repo_handle)
@@ -171,11 +177,15 @@
171177

172178
dstdir, dstname = os.path.split(dstpath)
173179

174-
pathlib.Path(dstdir).mkdir(parents=True, exist_ok=True)
175-
shutil.copyfile(srcpath, dstpath)
180+
if args.copy:
181+
pathlib.Path(dstdir).mkdir(parents=True, exist_ok=True)
182+
shutil.copyfile(srcpath, dstpath)
183+
184+
if args.verbose:
185+
sys.stdout.write("DEBUG: repo %s copy from '%s' to '%s' (%s)\n" % (repo_handle, str(srcpath), dstpath, shortpath))
186+
else:
187+
shortpath = "https://raw.githubusercontent.com/" + repodata["repo"] + "/" + repodata["branch"] + srcpath[len(gitdir):]
176188

177-
if args.verbose:
178-
sys.stdout.write("DEBUG: repo %s copy from '%s' to '%s' (%s)\n" % (repo_handle, str(srcpath), dstpath, shortpath))
179189

180190
images.append({
181191
'name': name,
@@ -195,7 +205,7 @@
195205
'data': repodata,
196206
'handle': repo_handle,
197207
'lastmodified': datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'),
198-
'name': repodata['name'] if 'name' in repodata else repodata['repo'],
208+
'name': repodata['name'] if 'name' in repodata else repo_handle,
199209
'provider': repodata['provider'],
200210
'provider_icon': 'https://www.vectorlogo.zone/logos/' + repodata['provider'] + '/' + repodata['provider'] + '-icon.svg',
201211
'url': giturl,
@@ -206,6 +216,7 @@
206216
if 'website' in repodata:
207217
data['website'] = repodata['website']
208218

219+
pathlib.Path(os.path.join(outputdir, repo_handle)).mkdir(parents=True, exist_ok=True)
209220
outputpath = os.path.join(outputdir, repo_handle, "sourceData.json")
210221

211222
outputfile = open(outputpath, 'w')

build-github.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# build the logo data
4+
#
5+
6+
set -o errexit
7+
set -o pipefail
8+
set -o nounset
9+
10+
echo "INFO: starting build at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
11+
12+
#
13+
# load an .env file if it exists
14+
#
15+
ENV_FILE=".env"
16+
if [ -f "${ENV_FILE}" ]; then
17+
echo "INFO: loading '${ENV_FILE}'"
18+
export $(cat "${ENV_FILE}")
19+
fi
20+
21+
OUTPUT_DIR=${OUTPUT_DIR:-./output}
22+
if [ ! -d "${OUTPUT_DIR}" ]; then
23+
echo "INFO: creating output directory ${OUTPUT_DIR}"
24+
mkdir -p "${OUTPUT_DIR}"
25+
fi
26+
27+
#
28+
# load all the git repos
29+
#
30+
echo "INFO: loading logos into ${OUTPUT_DIR}"
31+
./bin/loadrepo.py \
32+
--nocopy \
33+
--output=${OUTPUT_DIR} \
34+
--provider=github
35+
36+
# to force it to copy even if no new commits, add:
37+
# --always \
38+
39+
BUILD_DIR=${BUILD_DIR:-./build}
40+
if [ ! -d "${BUILD_DIR}" ]; then
41+
echo "INFO: creating build directory ${BUILD_DIR}"
42+
mkdir -p "${BUILD_DIR}"
43+
fi
44+
45+
#
46+
# make the index
47+
#
48+
echo "INFO: building compressed index"
49+
tar cvzf ${BUILD_DIR}/sourceData.tgz ${OUTPUT_DIR}/*/sourceData.json
50+
51+
echo "INFO: completed build at $(date -u +%Y-%m-%dT%H:%M:%SZ)"

0 commit comments

Comments
 (0)