How to use slash_version method in Slash

Best Python code snippet using slash

build_xpi.py

Source:build_xpi.py Github

copy

Full Screen

1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, You can obtain one at http://mozilla.org/MPL/2.0/.4# Generate xpi for the simulator addon by:5# - building a special gaia profile for it, as we need:6# * more languages, and,7# * less apps8# than b2g desktop's one9# - retrieve usefull app version metadata from the build system10# - finally, use addon sdk's cfx tool to build the addon xpi11# that ships:12# * a small firefox addon registering to the app manager13# * b2g desktop runtime14# * gaia profile15import sys, os, re, subprocess16from mozbuild.preprocessor import Preprocessor17from mozbuild.base import MozbuildObject18from mozbuild.util import ensureParentDir19from zipfile import ZipFile20from distutils.version import LooseVersion21ftp_root_path = "/pub/mozilla.org/labs/fxos-simulator"22UPDATE_LINK = "https://ftp.mozilla.org" + ftp_root_path + "/%(update_path)s/%(xpi_name)s"23UPDATE_URL = "https://ftp.mozilla.org" + ftp_root_path + "/%(update_path)s/update.rdf"24XPI_NAME = "fxos-simulator-%(version)s-%(platform)s.xpi"25class GaiaBuilder(object):26 def __init__(self, build, gaia_path):27 self.build = build28 self.gaia_path = gaia_path29 def clean(self):30 self.build._run_make(target="clean", directory=self.gaia_path)31 def profile(self, env):32 self.build._run_make(target="profile", directory=self.gaia_path, num_jobs=1, silent=False, append_env=env)33 def override_prefs(self, srcfile):34 # Note that each time we call `make profile` in gaia, a fresh new pref file is created35 # cat srcfile >> profile/user.js36 with open(os.path.join(self.gaia_path, "profile", "user.js"), "a") as userJs:37 userJs.write(open(srcfile).read())38def process_package_overload(src, dst, version, app_buildid):39 ensureParentDir(dst)40 # First replace numeric version like '1.3'41 # Then replace with 'slashed' version like '1_4'42 # Finally set the full length addon version like 1.3.2013123043 defines = {44 "NUM_VERSION": version,45 "SLASH_VERSION": version.replace(".", "_"),46 "FULL_VERSION": ("%s.%s" % (version, app_buildid))47 }48 pp = Preprocessor(defines=defines)49 pp.do_filter("substitution")50 with open(dst, "w") as output:51 with open(src, "r") as input:52 pp.processFile(input=input, output=output)53def add_dir_to_zip(zip, top, pathInZip, blacklist=()):54 zf = ZipFile(zip, "a")55 for dirpath, subdirs, files in os.walk(top):56 dir_relpath = os.path.relpath(dirpath, top)57 if dir_relpath.startswith(blacklist):58 continue59 zf.write(dirpath, os.path.join(pathInZip, dir_relpath))60 for filename in files:61 relpath = os.path.join(dir_relpath, filename)62 if relpath in blacklist:63 continue64 zf.write(os.path.join(dirpath, filename),65 os.path.join(pathInZip, relpath))66 zf.close()67def main(platform):68 build = MozbuildObject.from_environment()69 topsrcdir = build.topsrcdir70 distdir = build.distdir71 srcdir = os.path.join(topsrcdir, "b2g", "simulator")72 app_buildid = open(os.path.join(build.topobjdir, "config", "buildid")).read().strip()73 # The simulator uses a shorter version string,74 # it only keeps the major version digits A.B75 # whereas MOZ_B2G_VERSION is A.B.C.D76 b2g_version = build.config_environment.defines["MOZ_B2G_VERSION"].replace('"', '')77 version = ".".join(str(n) for n in LooseVersion(b2g_version).version[0:2])78 # Build a gaia profile specific to the simulator in order to:79 # - disable the FTU80 # - set custom prefs to enable devtools debugger server81 # - set custom settings to disable lockscreen and screen timeout82 # - only ship production apps83 gaia_path = build.config_environment.substs["GAIADIR"]84 builder = GaiaBuilder(build, gaia_path)85 builder.clean()86 env = {87 "NOFTU": "1",88 "GAIA_APP_TARGET": "production",89 "SETTINGS_PATH": os.path.join(srcdir, "custom-settings.json")90 }91 builder.profile(env)92 builder.override_prefs(os.path.join(srcdir, "custom-prefs.js"))93 # Substitute version strings in the package manifest overload file94 manifest_overload = os.path.join(build.topobjdir, "b2g", "simulator", "package-overload.json")95 process_package_overload(os.path.join(srcdir, "package-overload.json.in"),96 manifest_overload,97 version,98 app_buildid)99 # Build the simulator addon xpi100 xpi_name = XPI_NAME % {"version": version, "platform": platform}101 xpi_path = os.path.join(distdir, xpi_name)102 update_path = "%s/%s" % (version, platform)103 update_link = UPDATE_LINK % {"update_path": update_path, "xpi_name": xpi_name}104 update_url = UPDATE_URL % {"update_path": update_path}105 subprocess.check_call([106 build.virtualenv_manager.python_path, os.path.join(topsrcdir, "addon-sdk", "source", "bin", "cfx"), "xpi", \107 "--pkgdir", srcdir, \108 "--manifest-overload", manifest_overload, \109 "--strip-sdk", \110 "--update-link", update_link, \111 "--update-url", update_url, \112 "--static-args", "{\"label\": \"Firefox OS %s\"}" % version, \113 "--output-file", xpi_path \114 ])115 # Ship b2g-desktop, but prevent its gaia profile to be shipped in the xpi116 add_dir_to_zip(xpi_path, os.path.join(distdir, "b2g"), "b2g", ("gaia", "B2G.app/Contents/MacOS/gaia"))117 # Then ship our own gaia profile118 add_dir_to_zip(xpi_path, os.path.join(gaia_path, "profile"), "profile")119if __name__ == '__main__':120 if 2 != len(sys.argv):121 print("""Usage:122 python {0} MOZ_PKG_PLATFORM123""".format(sys.argv[0]))124 sys.exit(1)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...40 returned = func(args)41 if not isinstance(returned, int):42 returned = returned.exit_code43 return returned44def slash_version(_):45 print('Slash v{}'.format(__version__))46 return 047################################## Boilerplate ################################48_DEFAULT_LOG_LEVEL = logbook.WARNING49@contextlib.contextmanager50def _setup_logging_context(args):51 log_level = max(logbook.DEBUG, _DEFAULT_LOG_LEVEL - len(args.verbosity))52 with logbook.NullHandler().applicationbound():53 with logbook.StderrHandler(level=log_level, bubble=False).applicationbound():54 yield55#### For use with entry_points/console_scripts56def main_entry_point():57 is_windows = os.name == 'nt'58 if is_windows:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful