This is an experimental copy for testing Poikilos' issue mirroring system. Note that Gitea's migration tool can import issues, but the "Issues" checkbox is disabled when "This repository will be a mirror" is enabled (it is for this repo).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

193 lines
6.3 KiB

#!/usr/bin/env python3
from __future__ import print_function
import sys
import os
import platform
from pyenliven import (
echo0,
)
me = os.path.basename(__file__)
myDir = os.path.dirname(os.path.abspath(__file__))
defaultVirtualReposDir = myDir
def usage():
echo0("Usage:")
sys.stderr.write("Specify a branch")
parent = "Bucket_Game-branches"
if os.path.isdir(parent):
echo0(" from Bucket_Game-branches:")
for sub in os.listdir(parent):
subPath = os.path.join(parent, sub)
if sub.startswith("."):
continue
if os.path.isdir(subPath):
echo0(subPath)
else:
echo0(" from Bucket_Game-branches.")
echo0("{} <branch name (see above)> [<bucket_game path>]".format(me))
echo0("")
profile = None
if platform.system() == "Windows":
profile = os.environ.get('USERPROFILE')
if profile is None:
echo0("Error: USERPROFILE is not set.")
sys.exit(1)
else:
profile = os.environ.get('HOME')
if profile is None:
echo0("Error: HOME is not set.")
sys.exit(1)
minetestPath = os.path.join(profile, "minetest")
gamesPath = os.path.join(minetestPath, "games")
defaultGamePath = None
def compareBranch(branchName, gamePath=None, bgVersion=None,
bgVersionsPath=minetestPath, compareOld=False,
branchesPath=None,
vReposDir=defaultVirtualReposDir):
results = {}
'''
Keyword arguments:
gamePath -- Specify a bucket_game base path to which to compare.
bgVersion -- Specify a bucket_game version that is stored outside
of the games directory but directly in bgVersionsPath (If
bgVersion is not None, the function will fail if the directory
"bucket_game-{}".format(bgVersion) doesn't exist in
bgVersionsPath.
compareOld: Set to True to use
patchesDir = os.path.join(myDir, "Bucket_Game-base")
instead of
patchesDir = os.path.join(myDir, "Bucket_Game-branches")
(The option is ignored if branchesPath is set).
branchesPath -- Specify what directory contains the head branches.
vReposDir -- Specify what directory contains
Bucket_Game-branches and Bucket_Game-base (The option is ignored
if branchesPath is set).
Raises:
- ValueError if the bgVersion is neither specified nor detected
after "-vs-" in the patch name.
- ValueError if the bgVersion directory isn't found
- ValueError if the branch isn't found
'''
detectedBGVer = None
parts = branchName.split("-")
versionMsg = "specified"
if (len(parts) > 2) and (parts[-2] == "vs"):
detectedBGVer = parts[-1]
if os.path.sep in branchName:
branchName = os.path.split(branchName)[1]
myDirSlash = myDir + os.path.sep
if bgVersion is not None:
if detectedBGVer is not None:
print("WARNING: detected version {} but you specified {}"
"".format(detectedBGVer, bgVersion))
else:
bgVersion = detectedBGVer
versionMsg = "detected"
if compareOld:
if bgVersion is None:
raise ValueError("The game version was neither specified "
" nor after \"-vs-\" in the patch name.")
detectedGame = "bucket_game-{}".format(bgVersion)
# os.path.join(bgVersionsPath, detected)
detectedPath = os.path.join(bgVersionsPath, detected)
if not os.path.isdir(detectedPath):
usage()
raise ValueError("The {} game version is not present at"
" {}".format(versionMsg, detectedPath))
if branchesPath is None:
if compareOld:
branchesPath = os.path.join(vReposDir,
"Bucket_Game-base")
else:
branchesPath = os.path.join(vReposDir,
"Bucket_Game-branches")
if gamePath is None:
if compareOld:
gamePath = detectedPath
basePath = detectedPath
else:
tryGame = "bucket_game"
tryGamePath = os.path.join(gamesPath, tryGame)
if not os.path.isdir(tryGamePath):
tryGame = "Bucket_Game"
tryGamePath = os.path.join(gamesPath, tryGame)
gamePath = tryGamePath
basePath = os.path.join(vReposDir, "Bucket_Game-base",
branchName)
basePath = os.path.realpath(basePath)
if not os.path.isdir(gamePath):
usage()
raise ValueError("The {} game version is not present at"
" {}".format(versionMsg, gamePath))
branchPath = os.path.join(branchesPath, branchName)
if not os.path.isdir(branchPath):
raise ValueError("The branch wasn't found at \"{}\""
"".format(branchPath))
branchPath = os.path.realpath(branchPath)
basePathRel = basePath
if basePathRel.startswith(myDirSlash):
basePathRel = basePathRel[len(myDirSlash):]
gamePathRel = gamePath
if gamePathRel.startswith(myDirSlash):
gamePathRel = gamePathRel[len(myDirSlash):]
branchPathRel = branchPath
if branchPathRel.startswith(myDirSlash):
branchPathRel = branchPathRel[len(myDirSlash):]
print("meld \"{}\" \"{}\"".format(gamePath, branchPath))
patchFilePath = branchPath+".patch"
print("diff -ru \"{}\" \"{}\" > \"{}\""
"".format(basePathRel, branchPathRel, patchFilePath))
results = {
'gamePath': gamePath,
'branchPath': branchPath,
'patchFilePath': patchFilePath,
}
return results
def main():
global defaultGamePath
defaultGamePath = None
if len(sys.argv) < 2:
usage()
echo0("Error: You must provide a branch name.\n")
return 1
if len(sys.argv) > 3:
usage()
echo0("Error: There are too many arguments: {}.\n"
"".format(sys.argv))
return 1
if len(sys.argv) > 2:
defaultGamePath = sys.argv[2]
results = compareBranch(sys.argv[1], gamePath=defaultGamePath)
echo0("# ^ Do that to see the difference or generate a patch,"
" but the first directory must be unmodified from the"
" original release package.")
return 0
if __name__ == "__main__":
sys.exit(main())