Created
September 14, 2024 18:44
-
-
Save dotysan/f8a44fcf4a2f11fba1ec499179933117 to your computer and use it in GitHub Desktop.
Recreate a git repo from a bunch of PyPI releases.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# | |
# Recreate a git repo from a bunch of PyPI releases. | |
# | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
#set -o xtrace | |
PACKAGE=arcgis | |
REPO=arcgis-python | |
GHUSER=dotysan | |
main() { | |
rm -fr "$REPO" | |
reset_repo | |
setup_repo | |
get_all_rels | |
pkg2git | |
pushd "$REPO" | |
git push --set-upstream origin master | |
popd | |
rm -fr "$PACKAGE"-1* "$PACKAGE"-2* "$PACKAGE"-3* | |
gh gist create "$0" --public --desc 'Recreate a git repo from a bunch of PyPI releases.' | |
} | |
reset_repo() { | |
local repo="$GHUSER/$REPO" | |
if ! gh auth status | |
then | |
echo 'Paste a token from https://github.com/settings/tokens here, the press Ctrl-D to close stdin.' | |
gh auth login --hostname github.com --with-token | |
fi | |
# switch from https default to ssh | |
gh config set git_protocol ssh | |
# note, everything is stored in ~/.config/gh/ | |
if gh repo view "$repo" | |
then | |
gh repo delete "$repo" --confirm | |
fi | |
gh repo create "$repo" --description="ESRI's Python API reconstructed." --private --clone | |
} | |
setup_repo() { | |
pushd "$REPO" | |
cat >.gitattributes <<-EOF | |
# macros | |
[attr]lfs filter=lfs diff=lfs merge=lfs -text | |
# images | |
*.png lfs | |
# libraries | |
*.pyd lfs | |
*.so lfs | |
EOF | |
git lfs track | |
git add .gitattributes | |
git commit -m 'Enable git LFS for PNG images' | |
popd | |
} | |
get_all_rels() { | |
local rel tb tbmt bn mt | |
get_releases "$PACKAGE" |while read -r rel | |
do | |
tb="${rel##*/}" | |
if [[ ! -s "$tb" ]] | |
then wget -N "$rel" | |
fi | |
tbmt=$(stat -c%Y "$tb") | |
bn="${tb::-7}" | |
if [[ ! -d "$bn" ]] | |
then | |
mkdir "$bn" | |
pushd "$bn" | |
tar --extract --strip-components=1 --file="../$tb" | |
~/src/sh/lt.sh | |
popd | |
fi | |
done | |
} | |
get_releases() { | |
curl "https://pypi.org/pypi/$1/json" |jq --raw-output '.releases[] |.[] |.url' | |
} | |
pkg2git() { | |
local rel mt rev | |
# # extracted tarball subdirs sorted by mtime | |
# find -mindepth 1 -maxdepth 1 -type d -name '*[0-9]*' -printf '%T@ %p\n' \ | |
# |sort |while read -r mt rel | |
# extracted tarball subdirs sorted by name (will fail with 10 less than 9) | |
find -mindepth 1 -maxdepth 1 -type d -name '*[0-9]*' -printf '%T@ %p\n' \ | |
|sort -k2 |while read -r mt rel | |
do echo "$rel" | |
mt=$(date -d "@$mt" --rfc-2822) | |
rsync --archive --delete \ | |
--exclude=.git/ \ | |
--exclude=.gitattributes \ | |
--exclude='*/widgets/js/dist/*' \ | |
"$rel/" "$REPO/" | |
pushd "$REPO" | |
# no point in tracking bin libs | |
find -type f \( \ | |
-name '*.pyd' -o \ | |
-name '*.so' \ | |
\) -delete | |
# standardize \n without \r | |
find -type f \( \ | |
-name '*.cfg' -o \ | |
-name '*.css' -o \ | |
-name '*.in' -o \ | |
-name '*.js' -o \ | |
-name '*.json' -o \ | |
-name '*.md' -o \ | |
-name '*.py' -o \ | |
-name '*.ts' -o \ | |
-name '*.txt' -o \ | |
-name .gitignore -o \ | |
-name PKG-INFO \ | |
\) -print0 |xargs -r0 dos2unix --quiet | |
git add --all | |
rev="${rel##*-}" | |
GIT_COMMITTER_DATE="$mt" git commit --date="$mt" -m "$rev" ||: | |
popd | |
#if grep ^1 <<<"$rev" | |
#then echo good | |
#else read -n1 -p 'Press any key to continue...' </dev/tty | |
#fi | |
done | |
} | |
main | |
exit 0 | |
#git branch "$rev" | |
#git tag -a "$rev" -m "Release $rev" | |
#git push origin "$rev" | |
#git push origin "$rev" --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment