Python os.environ() Examples

The following are 30 code examples of os.environ(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source Project: aws-auto-remediate   Author: servian   File: lambda_handler.py    License: GNU General Public License v3.0 7 votes vote down vote up
def get_settings(self):
        """Return the DynamoDB aws-auto-remediate-settings table in a Python dict format
        
        Returns:
            dict -- aws-auto-remediate-settings table
        """
        settings = {}
        try:
            for record in boto3.client("dynamodb").scan(
                TableName=os.environ["SETTINGSTABLE"]
            )["Items"]:
                record_json = dynamodb_json.loads(record, True)
                settings[record_json["key"]] = record_json["value"]
        except:
            self.logging.error(
                f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'."
            )
            self.logging.error(sys.exc_info()[1])

        return settings 
Example #2
Source Project: indras_net   Author: gcallah   File: test_grid.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, methodName, prop_file="models/grid_for_test.props"):
        super().__init__(methodName=methodName)

        self.pa = props.read_props(MODEL_NM, prop_file)

        # Now we create a forest environment for our agents to act within:
        if self.pa["user_type"] == props.WEB:
            self.pa["base_dir"] = os.environ["base_dir"]

        # Now we create a minimal environment for our agents to act within:
        self.env = ge.GridEnv("Test grid env",
                         self.pa["grid_width"],
                         self.pa["grid_height"],
                         torus=False,
                         model_nm=MODEL_NM,
                         preact=True,
                         postact=True,
                         props=self.pa)

        for i in range(self.pa["num_agents"]):
            self.env.add_agent(gm.TestGridAgent(name="agent" + str(i),
                                           goal="taking up a grid space!"))

        self.env.add_agent(gm.TestGridAgent(name="agent for tracking",
                                       goal="taking up a grid space!")) 
Example #3
Source Project: godot-mono-builds   Author: godotengine   File: os_utils.py    License: MIT License 6 votes vote down vote up
def find_executable(name) -> str:
    is_windows = os.name == 'nt'
    windows_exts = os.environ['PATHEXT'].split(ENV_PATH_SEP) if is_windows else None
    path_dirs = os.environ['PATH'].split(ENV_PATH_SEP)

    search_dirs = path_dirs + [os.getcwd()] # cwd is last in the list

    for dir in search_dirs:
        path = os.path.join(dir, name)

        if is_windows:
            for extension in windows_exts:
                path_with_ext = path + extension

                if os.path.isfile(path_with_ext) and os.access(path_with_ext, os.X_OK):
                    return path_with_ext
        else:
            if os.path.isfile(path) and os.access(path, os.X_OK):
                return path

    return '' 
Example #4
Source Project: drydock   Author: airshipit   File: env.py    License: Apache License 2.0 6 votes vote down vote up
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    db_url = os.environ['DRYDOCK_DB_URL']

    connectable = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool,
        url=db_url)

    with connectable.connect() as connection:
        context.configure(
            connection=connection, target_metadata=target_metadata)

        with context.begin_transaction():
            context.run_migrations() 
Example #5
Source Project: aegea   Author: kislyuk   File: secrets.py    License: Apache License 2.0 6 votes vote down vote up
def put(args):
    if args.generate_ssh_key:
        ssh_key = new_ssh_key()
        buf = StringIO()
        ssh_key.write_private_key(buf)
        secret_value = buf.getvalue()
    elif args.secret_name in os.environ:
        secret_value = os.environ[args.secret_name]
    else:
        secret_value = sys.stdin.read()
    try:
        res = clients.secretsmanager.create_secret(Name=args.secret_name, SecretString=secret_value)
    except clients.secretsmanager.exceptions.ResourceExistsException:
        res = clients.secretsmanager.put_secret_value(SecretId=args.secret_name, SecretString=secret_value)
    if parse_principal(args):
        ensure_policy(parse_principal(args), res["ARN"])
    if args.generate_ssh_key:
        return dict(ssh_public_key=hostkey_line(hostnames=[], key=ssh_key).strip(),
                    ssh_key_fingerprint=key_fingerprint(ssh_key)) 
Example #6
Source Project: BASS   Author: Cisco-Talos   File: core.py    License: GNU General Public License v2.0 6 votes vote down vote up
def get_VT_name(hashes):
    try:
        vt = PrivateApi(api_key = os.environ["VIRUSTOTAL_API_KEY"])
        generator = ComputeVtUniqueName()
        names = [generator.build_unique_name(vt.get_file_report(hash_) or "") for hash_ in hashes]
        if len(names) >= 2 and all(names[0] == name for name in names[1:]):
            name = names[0]
            if name["pup"]:
                log.error("PUA signatures are not implemented yet. Excpected name was: %s", str(name))
                pass
            else:
                return "{}.{}.{}".format(name["platform"], name["category"], name["unique_name"])
    except KeyError:
        log.warn("No VIRUSTOTAL_API_KEY specified. Falling back to generic name.")
    except Exception:
        log.exception("White trying to compute VT name. Falling back to generic name.")
    return GENERIC_CLAMAV_MALWARE_NAME 
Example #7
Source Project: MPContribs   Author: materialsproject   File: views.py    License: MIT License 6 votes vote down vote up
def index(request):
    ctx = get_context(request)
    cname = os.environ["PORTAL_CNAME"]
    template_dir = get_app_template_dirs("templates/notebooks")[0]
    htmls = os.path.join(template_dir, cname, "*.html")
    ctx["notebooks"] = [
        p.split("/" + cname + "/")[-1].replace(".html", "") for p in glob(htmls)
    ]
    ctx["PORTAL_CNAME"] = cname
    ctx["landing_pages"] = []
    mask = ["project", "title", "authors", "is_public", "description", "urls"]
    client = Client(headers=get_consumer(request))  # sets/returns global variable
    entries = client.projects.get_entries(_fields=mask).result()["data"]
    for entry in entries:
        authors = entry["authors"].strip().split(",", 1)
        if len(authors) > 1:
            authors[1] = authors[1].strip()
        entry["authors"] = authors
        entry["description"] = entry["description"].split(".", 1)[0] + "."
        ctx["landing_pages"].append(
            entry
        )  # visibility governed by is_public flag and X-Consumer-Groups header
    return render(request, "home.html", ctx.flatten()) 
Example #8
Source Project: multibootusb   Author: mbusb   File: _device.py    License: GNU General Public License v2.0 6 votes vote down vote up
def from_environment(cls, context):
        """
        Create a new device from the process environment (as in
        :data:`os.environ`).

        This only works reliable, if the current process is called from an
        udev rule, and is usually used for tools executed from ``IMPORT=``
        rules.  Use this method to create device objects in Python scripts
        called from udev rules.

        ``context`` is the library :class:`Context`.

        Return a :class:`Device` object constructed from the environment.
        Raise :exc:`DeviceNotFoundInEnvironmentError`, if no device could be
        created from the environment.

        .. udevversion:: 152

        .. versionadded:: 0.18
        """
        device = context._libudev.udev_device_new_from_environment(context)
        if not device:
            raise DeviceNotFoundInEnvironmentError()
        return Device(context, device) 
Example #9
Source Project: aws-auto-remediate   Author: servian   File: lambda_handler.py    License: GNU General Public License v3.0 6 votes vote down vote up
def send_to_missing_remediation_topic(self, config_rule_name, config_payload):
        """Publishes a message onto the missing remediation SNS Topic. The topic should be subscribed to
        by administrators to be aware when their security remediations are not fully covered.
        
        Arguments:
            config_rule_name {string} -- AWS Config Rule name
            config_payload {dictionary} -- AWS Config Rule payload
        """
        client = boto3.client("sns")
        topic_arn = os.environ["MISSINGREMEDIATIONTOPIC"]

        try:
            client.publish(
                TopicArn=topic_arn,
                Message=json.dumps(config_payload),
                Subject=f"No remediation available for Config Rule '{config_rule_name}'",
            )
        except:
            self.logging.error(f"Could not publish to SNS Topic 'topic_arn'.") 
Example #10
Source Project: aws-auto-remediate   Author: servian   File: lambda_handler.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_settings(self):
        """Return the DynamoDB aws-auto-remediate-settings table in a Python dict format
        
        Returns:
            dict -- aws-auto-remediate-settings table
        """
        settings = {}
        try:
            for record in self.client_dynamodb.scan(
                TableName=os.environ["SETTINGSTABLE"]
            )["Items"]:
                record_json = dynamodb_json.loads(record, True)

                if "key" in record_json and "value" in record_json:
                    settings[record_json.get("key")] = record_json.get("value")
        except:
            self.logging.error(
                f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'."
            )
            self.logging.error(sys.exc_info()[1])

        return settings 
Example #11
Source Project: aws-auto-remediate   Author: servian   File: test_setup.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_invalid_table_schema(self, setup):
        """Tests retrieval of settings from DynamoDB with the wrong schema
        
        Arguments:
            setup {class} -- Instance of Setup class
        """
        os.environ["SETTINGSTABLE"] = "settings-table"

        setup.client_dynamodb.create_table(
            TableName="settings-table",
            KeySchema=[{"AttributeName": "id", "KeyType": "HASH"}],
            AttributeDefinitions=[{"AttributeName": "id", "AttributeType": "S"}],
            ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
        )

        setup.client_dynamodb.put_item(
            TableName="settings-table", Item={"id": {"S": "123"}}
        )

        # test get_settings function
        assert setup.get_settings() == {} 
Example #12
Source Project: CAMISIM   Author: CAMI-challenge   File: configparserwrapper.py    License: Apache License 2.0 6 votes vote down vote up
def _get_full_path(value):
		"""
			convert string to absolute normpath.

			@param value: some string to be converted
			@type value: basestring

			@return: absolute normpath
			@rtype: basestring
		"""
		assert isinstance(value, basestring)
		parent_directory, filename = os.path.split(value)
		if not parent_directory and not os.path.isfile(value):
			for path in os.environ["PATH"].split(os.pathsep):
				path = path.strip('"')
				exe_file = os.path.join(path, filename)
				if os.path.isfile(exe_file):
					value = exe_file
					break
		value = os.path.expanduser(value)
		value = os.path.normpath(value)
		value = os.path.abspath(value)
		return value 
Example #13
Source Project: friendly-telegram   Author: friendly-telegram   File: updater.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def update_complete(self, client):
        logger.debug("Self update successful! Edit message")
        heroku_key = os.environ.get("heroku_api_token")
        herokufail = ("DYNO" in os.environ) and (heroku_key is None)
        if herokufail:
            logger.warning("heroku token not set")
            msg = self.strings["heroku_warning"]
        else:
            logger.debug("Self update successful! Edit message")
            msg = self.strings["success"] if random.randint(0, 10) != 0 else self.strings["success_meme"]
        if self.config["AUDIO"]:
            await client.send_file(self._db.get(__name__, "selfupdatechat"), STARTUP, caption=msg, voice_note=True)
            await client.delete_messages(self._db.get(__name__, "selfupdatechat"),
                                         [self._db.get(__name__, "selfupdatemsg")])
        else:
            await client.edit_message(self._db.get(__name__, "selfupdatechat"),
                                      self._db.get(__name__, "selfupdatemsg"), msg) 
Example #14
Source Project: friendly-telegram   Author: friendly-telegram   File: main.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def get_phones(arguments):
    """Get phones from the --token, --phone, and environment"""
    phones = set(arguments.phone if arguments.phone else [])
    phones.update(map(lambda f: f[18:-8],
                      filter(lambda f: f.startswith("friendly-telegram-") and f.endswith(".session"),
                             os.listdir(os.path.dirname(utils.get_base_dir())))))

    authtoken = os.environ.get("authorization_strings", False)  # for heroku
    if authtoken and not arguments.setup:
        try:
            authtoken = json.loads(authtoken)
        except json.decoder.JSONDecodeError:
            logging.warning("authtoken invalid")
            authtoken = False

    if arguments.setup or (arguments.tokens and not authtoken):
        authtoken = {}
    if arguments.tokens:
        for token in arguments.tokens:
            phone = sorted(phones).pop(0)
            phones.remove(phone)  # Handled seperately by authtoken logic
            authtoken.update(**{phone: token})
    return phones, authtoken 
Example #15
Source Project: supervisor-logging   Author: infoxchange   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def main():
    """
    Main application loop.
    """

    env = os.environ

    try:
        host = env['SYSLOG_SERVER']
        port = int(env['SYSLOG_PORT'])
        socktype = socket.SOCK_DGRAM if env['SYSLOG_PROTO'] == 'udp' \
            else socket.SOCK_STREAM
    except KeyError:
        sys.exit("SYSLOG_SERVER, SYSLOG_PORT and SYSLOG_PROTO are required.")

    handler = SysLogHandler(
        address=(host, port),
        socktype=socktype,
    )
    handler.setFormatter(PalletFormatter())

    for event_headers, event_data in supervisor_events(sys.stdin, sys.stdout):
        event = logging.LogRecord(
            name=event_headers['processname'],
            level=logging.INFO,
            pathname=None,
            lineno=0,
            msg=event_data,
            args=(),
            exc_info=None,
        )
        event.process = int(event_headers['pid'])
        handler.handle(event) 
Example #16
Source Project: indras_net   Author: gcallah   File: prop_args2.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_prop_from_env():
    global user_type
    try:
        user_type = os.environ[UTYPE]
    except KeyError:
# this can't be done before logging is set up!
#        logging.info("Environment variable user type not found")
        user_type = TERMINAL
    return user_type 
Example #17
Source Project: indras_net   Author: gcallah   File: prop_args2.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, model_nm, logfile=None, prop_dict=None,
                 loglevel=logging.INFO):
        """
        Loads and sets properties in the following order:
        1. The Database
        2. The User's Environment (operating system, dev/prod settings, etc.)
        3. Property File
        4. Command Line
        5. Questions Prompts During Run-Time
        """
        self.logfile = logfile
        self.model_nm = model_nm
        self.graph = nx.Graph()
        self.props = {}

        # 1. The Database
        self.set_props_from_db()

        # 2. The Environment
        self.overwrite_props_from_env()

        # 3. Property File
        self.overwrite_props_from_dict(prop_dict)

        if self.props[UTYPE].val in (TERMINAL, IPYTHON, IPYTHON_NB):
            # 4. process command line args and set them as properties:
            self.overwrite_props_from_cl()

            # 5. Ask the user questions.
            self.overwrite_props_from_user()

        elif self.props[UTYPE].val == WEB:
            self.props[PERIODS] = Prop(val=1)
            self.props[BASE_DIR] = Prop(val=os.environ[BASE_DIR])

        self.logger = Logger(self, model_name=model_nm, logfile=logfile)
        self.graph.add_edge(self, self.logger) 
Example #18
Source Project: indras_net   Author: gcallah   File: prop_args.py    License: GNU General Public License v3.0 5 votes vote down vote up
def get_prop_from_env(prop_nm):
    global user_type
    try:
        user_type = os.environ['user_type']
    except KeyError:
# this can't be done before logging is set up!
#        logging.info("Environment variable user type not found")
        user_type = TERMINAL
    return user_type 
Example #19
Source Project: indras_net   Author: gcallah   File: segregation_run.py    License: GNU General Public License v3.0 5 votes vote down vote up
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import indra.utils as utils
    import schelling.segregation as sm

    # set up some file names:
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    # We store basic parameters in a "property" file; this allows us to save
    #  multiple parameter sets, which is important in simulation work.
    #  We can read these in from file or set them here.

    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ['base_dir']
        
    # Now we create an environment for our agents to act within:
    env = sm.SegregationEnv("A city",
                            pa["grid_width"],
                            pa["grid_height"],
                            model_nm=pa.model_nm,
                            props=pa)
    
    # Now we loop creating multiple agents with numbered names
    # based on the loop variable:
    for i in range(pa["num_B_agents"]):
        env.add_agent(sm.BlueAgent(name="Blue agent" + str(i),
                      goal="A good neighborhood.",
                      min_tol=pa['min_tolerance'],
                      max_tol=pa['max_tolerance'],
                      max_detect=pa['max_detect']))
        
    for i in range(pa["num_R_agents"]):
        env.add_agent(sm.RedAgent(name="Red agent" + str(i),
                      goal="A good neighborhood.",
                      min_tol=pa['min_tolerance'],
                      max_tol=pa['max_tolerance'],
                      max_detect=pa['max_detect']))
        
    return utils.run_model(env, prog_file, results_file) 
Example #20
Source Project: indras_net   Author: gcallah   File: party_run.py    License: GNU General Public License v3.0 5 votes vote down vote up
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import indra.utils as utils
    import models.party as pm

    # set up some file names:
    (prog_file, log_file, prop_file,
     results_file) = utils.gen_file_names(MODEL_NM)
    # We store basic parameters in a "property" file; this allows us to save
    #  multiple parameter sets, which is important in simulation work.
    #  We can read these in from file or set them here.

    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ['base_dir']

    # Now we create an environment for our agents to act within:
    env = pm.PartyEnv("A cocktail party",
                            pa["grid_width"],
                            pa["grid_height"],
                            model_nm=pa.model_nm,
                            props=pa)

    # Now we loop creating multiple agents with numbered names
    # based on the loop variable:
    for i in range(pa["num_men"]):
        env.add_agent(pm.Man(name="Man" + str(i),
                      goal="A good party.",
                      tol=0.5,
                      max_detect=pa['max_detect']))

    for i in range(pa["num_women"]):
        env.add_agent(pm.Woman(name="Woman" + str(i),
                      goal="A good party.",
                      tol=0.5,
                      max_detect=pa['max_detect']))

    return utils.run_model(env, prog_file, results_file) 
Example #21
Source Project: indras_net   Author: gcallah   File: gridang_run.py    License: GNU General Public License v3.0 5 votes vote down vote up
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import indra.utils as utils
    import indra.grid_env as ge
    import models.grid as gm
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ["base_dir"]
    
    # Now we create a minimal environment for our agents to act within:
    env = ge.GridEnv("Test grid env",
                     pa["grid_width"],
                     pa["grid_height"],
                     torus=False,
                     model_nm=MODEL_NM,
                     preact=True,
                     postact=True,
                     props=pa)
    
    # Now we loop creating multiple agents with numbered names
    # based on the loop variable:
    for i in range(pa["num_agents"]):
        env.add_agent(gm.TestGridAgent(name="agent" + str(i),
                      goal="taking up a grid space!"))
    
    # let's test our iterator
    for cell in env:
        (x, y) = cell.coords
        logging.info("Contents of cell x = " + str(x)
              + " and y = " + str(y)
              + " is " + str(cell.contents))
        
    return utils.run_model(env, prog_file, results_file) 
Example #22
Source Project: indras_net   Author: gcallah   File: forestfire_run.py    License: GNU General Public License v3.0 5 votes vote down vote up
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import indra.utils as utils
    import models.forestfire as fm
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    
    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ["base_dir"]
    
    grid_x = pa["grid_width"]
    grid_y = pa["grid_height"]
    density = pa["density"]

    # Now we create a forest environment for our agents to act within:
    env = fm.ForestEnv(grid_x,
                       grid_y,
                       density,
                       pa["strike_freq"],
                       pa["regen_period"],
                       model_nm=MODEL_NM,
                       torus=False,
                       props=pa)
    
    num_agents = int(grid_x * grid_y * density)
    
    for i in range(num_agents):
        env.add_agent(fm.Tree(name="tree" + str(i)))
    
    return utils.run_model(env, prog_file, results_file) 
Example #23
Source Project: indras_net   Author: gcallah   File: test_party.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, methodName, prop_file="models/party_for_test.props"):
        super().__init__(methodName=methodName)

        self.pa = props.read_props(MODEL_NM, prop_file)

        # Now we create a forest environment for our agents to act within:
        if self.pa["user_type"] == props.WEB:
            self.pa["base_dir"] = os.environ['base_dir']

        # Now we create an environment for our agents to act within:
        self.env = pm.PartyEnv("A cocktail party",
                          self.pa["grid_width"],
                          self.pa["grid_height"],
                          model_nm=self.pa.model_nm,
                          props=self.pa)

        for i in range(self.pa["num_men"]):
            self.env.add_agent(pm.Man(name="Man" + str(i),
                                 goal="A good party.",
                                 tol=0.5,
                                 max_detect=self.pa['max_detect']))

        for i in range(self.pa["num_women"]):
            self.env.add_agent(pm.Woman(name="Woman" + str(i),
                                   goal="A good party.",
                                   tol=0.5,
                                   max_detect=self.pa['max_detect']))

        self.env.add_agent(pm.Woman(name="Woman for tracking",
                                         goal="A good party.",
                                         tol=0.5,
                                         max_detect=self.pa['max_detect'])) 
Example #24
Source Project: svviz   Author: svviz   File: runTests.py    License: MIT License 5 votes vote down vote up
def getHG19Ref(path=None):
    if path is not None:
        os.environ["SVVIZ_HG19_FASTA"] = path
        return path

    path = os.environ.get("SVVIZ_HG19_FASTA", None)
    assert os.path.exists(path), "Can't find hg19 reference fasta at path '{}'".format(path)

    return path 
Example #25
Source Project: jumpserver-python-sdk   Author: jumpserver   File: test_auth.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_load_from_env(self):
        env_var = "XX_ACCESS_KEY"
        os.environ[env_var] = self.access_key_val
        access_key = AccessKey()
        access_key.load_from_env(env_var)
        self.assertEqual(access_key, self.access_key) 
Example #26
Source Project: jumpserver-python-sdk   Author: jumpserver   File: test_auth.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_load_from_conf_env(self):
        os.environ[self.key_env_var] = self.access_key_val
        app_access_key = deepcopy(self.app_access_key)
        app_access_key.load_from_conf_env()
        self.assertEqual(app_access_key, self.access_key) 
Example #27
Source Project: clikit   Author: sdispater   File: terminal.py    License: MIT License 5 votes vote down vote up
def _get_terminal_size_linux(self):
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios

                cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
                return cr
            except:
                pass

        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass

        if not cr:
            try:
                cr = (os.environ["LINES"], os.environ["COLUMNS"])
            except:
                return None

        return int(cr[1]), int(cr[0]) 
Example #28
Source Project: mlbv   Author: kmac   File: mlbv.py    License: GNU General Public License v3.0 5 votes vote down vote up
def display_usage():
    """Displays contents of readme file."""
    current_dir = os.path.dirname(inspect.getfile(inspect.currentframe()))
    readme_path = os.path.abspath(os.path.join(current_dir, '..', 'README.md'))
    if not os.path.exists(readme_path):
        print("Could not find documentation file [expected at: {}]".format(readme_path))
        return -1
    if 'PAGER' in os.environ:
        cmd = [os.environ['PAGER'], readme_path]
        subprocess.run(cmd)
    else:
        with open(readme_path, 'r') as infile:
            for line in infile:
                print(line, end='')
    return 0 
Example #29
Source Project: godot-mono-builds   Author: godotengine   File: desktop.py    License: MIT License 5 votes vote down vote up
def get_osxcross_sdk(osxcross_bin, arch):
    osxcross_sdk = os.environ.get('OSXCROSS_SDK', 18)

    name_fmt = path_join(osxcross_bin, arch + '-apple-darwin%s-%s')

    if not os.path.isfile(name_fmt % (osxcross_sdk, 'ar')):
        raise BuildError('Specify a valid osxcross SDK with the environment variable \'OSXCROSS_SDK\'')

    return osxcross_sdk 
Example #30
Source Project: godot-mono-builds   Author: godotengine   File: runtime.py    License: MIT License 5 votes vote down vote up
def setup_runtime_cross_template(env: dict, opts: RuntimeOpts, product: str, target: str, host_triple: str,
                target_triple: str, device_target: str, llvm: str, offsets_dumper_abi: str):
    CONFIGURE_FLAGS = [
        '--target=%s' % target_triple,
        '--with-cross-offsets=%s.h' % target_triple,
        '--with-llvm=%s/llvm-%s' % (opts.install_dir, llvm)
    ]

    env['_cross-runtime_%s-%s_CONFIGURE_FLAGS' % (product, target)] = CONFIGURE_FLAGS

    new_offsets_tool_path = '%s/mono/tools/offsets-tool/offsets-tool.py' % opts.mono_source_root
    old_offsets_tool_path = '%s/tools/offsets-tool-py/offsets-tool.py' % opts.mono_source_root

    old_offsets_tool = not os.path.isfile(new_offsets_tool_path)

    offsets_tool_env = None

    if old_offsets_tool:
        # Setup old offsets-tool-py if present (new location doesn't require setup)
        run_command('make', ['-C', '%s/tools/offsets-tool-py' % opts.mono_source_root, 'setup'], name='make offsets-tool-py')

        # Run offsets-tool in its virtual env
        virtualenv_vars = source('%s/tools/offsets-tool-py/offtool/bin/activate' % opts.mono_source_root)

        offsets_tool_env = os.environ.copy()
        offsets_tool_env.update(virtualenv_vars)

    build_dir = '%s/%s-%s-%s' % (opts.configure_dir, product, target, opts.configuration)
    mkdir_p(build_dir)

    run_command('python3', [
            old_offsets_tool_path if old_offsets_tool else new_offsets_tool_path,
            '--targetdir=%s/%s-%s-%s' % (opts.configure_dir, product, device_target, opts.configuration),
            '--abi=%s' % offsets_dumper_abi,
            '--monodir=%s' % opts.mono_source_root,
            '--outfile=%s/%s.h' % (build_dir, target_triple)
        ] + env['_%s-%s_OFFSETS_DUMPER_ARGS' % (product, target)],
        env=offsets_tool_env, name='offsets-tool')

    # Runtime template
    setup_runtime_template(env, opts, product, target, host_triple)