Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Implement some small improvements to export_mc #2948

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions bin/export_mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


def runProcess(cmd, cwd, errorMessage):
print "runProcess ", cmd
print("runProcess %s" % " ".join(cmd))
p = subprocess.Popen(cmd, cwd=cwd)

result = p.wait()
Expand All @@ -58,7 +58,7 @@ def __init__(self, mcRepoPath):
self.repoPath = mcRepoPath

def checkoutDefault(self, baseCommit):
print "Checking out default"
print("Checking out default")
if self.isGit:
if self.repo.active_branch.name != "default":
self.repo.heads.default.checkout()
Expand All @@ -67,7 +67,7 @@ def checkoutDefault(self, baseCommit):
"Failed to check out default branch: %s")

def createBranch(self, branch):
print "Creating new branch %s" % branch
print("Creating new branch %s" % branch)

if self.isGit:
self.repo.create_head(branch)
Expand All @@ -78,7 +78,7 @@ def createBranch(self, branch):
"Failed to create branch: %s")

def createCommit(self, subDir, commitMessage):
print "Creating commit..."
print("Creating commit...")

if self.isGit:
# Can't find a way to do this via gitPython APIs, so do it manually.
Expand All @@ -96,7 +96,7 @@ def createCommit(self, subDir, commitMessage):


def exportFilesToMC(repoDir, mcRepoLoc):
print "Exporting files"
print("Exporting files")

# Remove the existing files, except for ones we need to keep.
for root, dirs, files in os.walk(mcRepoLoc):
Expand All @@ -115,22 +115,22 @@ def exportFilesToMC(repoDir, mcRepoLoc):
for file in files:
filePath = os.path.join(root, file)
if file == "messages.json" and os.path.getsize(filePath) == 2:
print "Skipping empty locale file: %s" % filePath
print("Skipping empty locale file: %s" % filePath)
elif file == "messages.json" and 'en_US' not in root and filecmp.cmp(enUSFile, filePath):
print "Skipping same as en-US locale file: %s" % filePath
print("Skipping same as en-US locale file: %s" % filePath)
elif file not in FILES_TO_SKIP_COPY:
copyfile(filePath,
os.path.join(mcRepoLoc, relativePath, file))

for dir in dirs:
dirPath = os.path.join(mcRepoLoc, relativePath, dir)
if not os.path.exists(dirPath):
os.mkdir(dirPath, 0755)
os.mkdir(dirPath, 0o755)

# Copy the test files.
mc_test_loc = os.path.join(mcRepoLoc, "test", "browser")
if not os.path.exists(mc_test_loc):
os.makedirs(mc_test_loc, 0755)
os.makedirs(mc_test_loc, 0o755)

for root, dirs, files in os.walk(testDir):
for file in files:
Expand All @@ -143,8 +143,8 @@ def exportFilesToMC(repoDir, mcRepoLoc):


def exportToMozillaCentral(server, repoDir, mcRepoPath, mcSubDir, mcBranch,
noSwitchBranch, mcBaseCommit, commitMessage):
print "Exporting to m-c"
noSwitchBranch, mcBaseCommit, commitMessage, noCommit):
print("Exporting to m-c")

os.environ["SCREENSHOTS_SENTRY"] = SENTRY_ENDPOINTS[server]
os.environ["SCREENSHOTS_BACKEND"] = DEFAULTS[server]
Expand All @@ -157,33 +157,34 @@ def exportToMozillaCentral(server, repoDir, mcRepoPath, mcSubDir, mcBranch,

repo.createBranch(mcBranch)

print "Exporting this repository to mozilla-central..."
print("Exporting this repository to mozilla-central...")

runProcess(['make', 'clean'], repoDir, "Failed to make clean: %s")

runProcess(['make', 'addon'], repoDir, "Failed to make addon: %s")

exportFilesToMC(repoDir, os.path.join(mcRepoPath, "browser", "extensions", "screenshots"))

repo.createCommit(mcSubDir, commitMessage)
if not noCommit:
repo.createCommit(mcSubDir, commitMessage)


def buildMozillaCentral(mcRepoPath):
print "Building..."
print("Building...")

runProcess(['./mach', 'build'], mcRepoPath, "Failed to build in mc repo: %s")


def runTestsInMozillaCentral(mcRepoPath, mcSubDir):
print "Testing..."
print("Testing...")

runProcess(['./mach', 'test', mcSubDir], mcRepoPath,
"Tests failed! %s \n"
"mozilla-central directory may have been left in unclean state.")


def pushToTry(mcRepoPath, pushTry, onePlatform):
print "Pushing to try"
print("Pushing to try")

platforms = "linux,linux64,macosx64,win32,win64"
if onePlatform:
Expand All @@ -199,11 +200,11 @@ def pushToTry(mcRepoPath, pushTry, onePlatform):

def main(server, mcRepoPath, mcSubDir, mcBranch, noSwitchBranch,
mcBaseCommit, commitMessage,
build=False, runTests=False, pushTry=False, onePlatform=False):
build=False, runTests=False, pushTry=False, onePlatform=False, noCommit=False):
repoDir = os.path.dirname(os.path.realpath(os.path.join(__file__, "..")))

exportToMozillaCentral(server, repoDir, mcRepoPath, mcSubDir, mcBranch,
noSwitchBranch, mcBaseCommit, commitMessage)
noSwitchBranch, mcBaseCommit, commitMessage, noCommit)

if build:
buildMozillaCentral(mcRepoPath)
Expand Down Expand Up @@ -237,8 +238,10 @@ def main(server, mcRepoPath, mcSubDir, mcBranch, noSwitchBranch,
default="central",
help="The base commit if using Mercurial, defaults to 'central' (tree label)")
parser.add_argument("-m", "--commit-message",
required=True,
help="The commit message to use for the export.")
parser.add_argument("--no-commit",
action="store_true",
help="Leave the results uncommitted")
parser.add_argument("--build",
action="store_true",
help="Specify to build locally after export.")
Expand All @@ -253,11 +256,17 @@ def main(server, mcRepoPath, mcSubDir, mcBranch, noSwitchBranch,
help="Specify to push to only one platform for the try "
"build (linux64). Default is all platforms.")
args = parser.parse_args()
if not args.no_switch_branch and not args.branch:
print("You must give --branch BRANCH or --no-switch-branch")
sys.exit(1)
if not args.no_commit and not args.commit_message:
print("You must give -m/--commit-message MESSAGE or --no-commit")
sys.exit(1)

main(server=args.server, mcRepoPath=args.mozilla_central_repo,
mcSubDir=args.mozilla_central_subdir,
mcBaseCommit=args.mozilla_central_base_commit, mcBranch=args.branch,
noSwitchBranch=args.no_switch_branch,
commitMessage=args.commit_message, build=args.build,
runTests=args.run_tests, pushTry=args.push_to_try,
onePlatform=args.single_platform)
onePlatform=args.single_platform, noCommit=args.no_commit)