|
24 | 24 | parser.add_argument("--always", help="always process", default=False, dest='always', action="store_true")
|
25 | 25 | parser.add_argument("--branch", help="git branch (default='%s')" % default_branch, action="store", default=default_branch)
|
26 | 26 | 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="") |
27 | 28 | parser.add_argument("--input", help="YAML of potential repos", action="store", default="data/sources.yaml")
|
28 | 29 | parser.add_argument("--output", help="output directory", action="store", default="./local")
|
29 | 30 | parser.add_argument("--nocleanup", help="do not erase temporary files", default=True, dest='cleanup', action="store_false")
|
30 | 31 | 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') |
31 | 33 | parser.add_argument("--provider", help="only do specific provider", action="store", default="*", dest="provider")
|
32 | 34 | parser.add_argument('repos', help='repos (all if none specified)', metavar='repos', nargs='*')
|
33 | 35 |
|
|
88 | 90 | if os.path.isdir(gitdir):
|
89 | 91 | os.chdir(gitdir)
|
90 | 92 |
|
91 |
| - cached_commit = sh.git("rev-parse", "HEAD") |
| 93 | + cached_commit = sh.git("rev-parse", "HEAD", "--", _err_to_out=True, _out=sys.stdout) |
92 | 94 |
|
93 | 95 | if args.verbose:
|
94 | 96 | 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) |
96 | 98 | if args.verbose:
|
97 | 99 | sys.stdout.write("INFO: pull complete\n")
|
98 | 100 |
|
99 |
| - current_commit = sh.git("rev-parse", "HEAD") |
| 101 | + current_commit = sh.git("rev-parse", "HEAD", _err_to_out=True, _out=sys.stdout) |
100 | 102 | if cached_commit == current_commit:
|
101 | 103 | if args.always:
|
102 | 104 | sys.stdout.write("INFO: no changes to repo since last run but processing anyway\n")
|
|
105 | 107 | continue
|
106 | 108 | else:
|
107 | 109 | 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") |
113 | 134 |
|
114 | 135 | if args.verbose:
|
115 | 136 | 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) |
117 | 138 |
|
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) |
119 | 142 |
|
120 | 143 | logodir = os.path.join(gitdir, repodata['directory'])
|
121 | 144 | if args.verbose:
|
|
183 | 206 |
|
184 | 207 | if args.verbose:
|
185 | 208 | 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 |
186 | 211 | 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):] |
188 | 213 |
|
189 | 214 |
|
190 | 215 | images.append({
|
191 | 216 | 'name': name,
|
192 | 217 | 'src': giturl + "/blob/" + repodata['branch'] + srcpath[len(gitdir):],
|
193 |
| - 'img': shortpath |
| 218 | + 'img': imgurl |
194 | 219 | })
|
195 | 220 |
|
196 | 221 | sys.stdout.write("OUTPUT: %d svg files found for %s (%s)\n" % (len(images), repo_handle, repodata['repo']))
|
|
204 | 229 | data = {
|
205 | 230 | 'data': repodata,
|
206 | 231 | 'handle': repo_handle,
|
207 |
| - 'lastmodified': datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'), |
| 232 | + 'lastmodified': last_mod, |
208 | 233 | 'name': repodata['name'] if 'name' in repodata else repo_handle,
|
209 | 234 | 'provider': repodata['provider'],
|
210 | 235 | 'provider_icon': 'https://www.vectorlogo.zone/logos/' + repodata['provider'] + '/' + repodata['provider'] + '-icon.svg',
|
|
0 commit comments