Python os.getenv() Examples
The following are 30
code examples of os.getenv().
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 File: kerberos.py From incubator-spot with Apache License 2.0 | 7 votes |
def __init__(self): self._logger = Util.get_logger('SPOT.COMMON.KERBEROS') principal, keytab, sasl_mech, security_proto = config.kerberos() if os.getenv('KINITPATH'): self._kinit = os.getenv('KINITPATH') else: self._kinit = "kinit" self._kinitopts = os.getenv('KINITOPTS') self._keytab = "-kt {0}".format(keytab) self._krb_user = principal if self._kinit == None or self._keytab == None or self._krb_user == None: self._logger.error("Please verify kerberos configuration, some environment variables are missing.") sys.exit(1) if self._kinitopts is None: self._kinit_cmd = "{0} {1} {2}".format(self._kinit, self._keytab, self._krb_user) else: self._kinit_cmd = "{0} {1} {2} {3}".format(self._kinit, self._kinitopts, self._keytab, self._krb_user)
Example #2
Source File: epr.py From epr with MIT License | 6 votes |
def loadstate(): global STATE, STATEFILE if os.getenv("HOME") is not None: STATEFILE = os.path.join(os.getenv("HOME"), ".epr") if os.path.isdir(os.path.join(os.getenv("HOME"), ".config")): configdir = os.path.join(os.getenv("HOME"), ".config", "epr") os.makedirs(configdir, exist_ok=True) if os.path.isfile(STATEFILE): if os.path.isfile(os.path.join(configdir, "config")): os.remove(os.path.join(configdir, "config")) shutil.move(STATEFILE, os.path.join(configdir, "config")) STATEFILE = os.path.join(configdir, "config") elif os.getenv("USERPROFILE") is not None: STATEFILE = os.path.join(os.getenv("USERPROFILE"), ".epr") else: STATEFILE = os.devnull if os.path.exists(STATEFILE): with open(STATEFILE, "r") as f: STATE = json.load(f)
Example #3
Source File: task_tracking_table.py From aws-ops-automator with Apache License 2.0 | 6 votes |
def _run_local_stream_event(table, table_action, new_item, old_item=None, context=None): # if not running in lambda environment create event that normally results from dynamodb inserts and pass directly # to the main lambda handler to simulate an event triggered by the dynamodb stream if old_item is None: old_item = {} account = os.getenv(handlers.ENV_OPS_AUTOMATOR_ACCOUNT) region = services.get_session().region_name event = { "Records": [ { "eventName": table_action, "eventSourceARN": "arn:aws:dynamodb:{}:{}:table/{}/stream/{}".format(region, account, table, datetime.utcnow().isoformat()), "eventSource": "aws:dynamodb", "dynamodb": { "NewImage": build_record(new_item), "OldImage": build_record(old_item) } }] } handler = handlers.get_class_for_handler("TaskTrackingHandler")(event, context) handler.handle_request()
Example #4
Source File: os_utils.py From godot-mono-builds with MIT License | 6 votes |
def get_emsdk_root(): # Shamelessly copied from Godot's detect.py em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten') if not os.path.exists(em_config_file): raise BuildError("Emscripten configuration file '%s' does not exist" % em_config_file) with open(em_config_file) as f: em_config = {} try: # Emscripten configuration file is a Python file with simple assignments. exec(f.read(), em_config) except StandardError as e: raise BuildError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e)) if 'BINARYEN_ROOT' in em_config and os.path.isdir(os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten')): # New style, emscripten path as a subfolder of BINARYEN_ROOT return os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten') elif 'EMSCRIPTEN_ROOT' in em_config: # Old style (but can be there as a result from previous activation, so do last) return em_config.get('EMSCRIPTEN_ROOT') else: raise BuildError("'BINARYEN_ROOT' or 'EMSCRIPTEN_ROOT' missing in Emscripten configuration file '%s'" % em_config_file)
Example #5
Source File: task_configuration.py From aws-ops-automator with Apache License 2.0 | 6 votes |
def remove_stack_event_topic_permissions(self): """ Removes all permissions for accounts for putting events on the event bus of the Ops Automator account. Only permissions created by this stack are removed. :return: """ topic_arn = os.getenv(handlers.ENV_EVENTS_TOPIC_ARN) sns_client = boto_retry.get_client_with_retries("sns", methods=["remove_permission", "get_topic_attributes"], context=self._context) statement = json.loads(sns_client.get_topic_attributes_with_retries( TopicArn=topic_arn).get("Attributes", {}).get("Policy", "{}")).get("Statement", []) permission_sids_for_stack = [s["Sid"] for s in statement if s["Sid"].startswith(TaskConfiguration._event_bus_permissions_sid_prefix())] for label in permission_sids_for_stack: sns_client.remove_permission_with_retries(Label=label, TopicArn=topic_arn)
Example #6
Source File: util.py From wechat-alfred-workflow with MIT License | 6 votes |
def run_trigger(name, bundleid=None, arg=None): """Call an Alfred External Trigger. .. versionadded:: 1.31 If ``bundleid`` is not specified, reads the bundle ID of the current workflow from Alfred's environment variables. Args: name (str): Name of External Trigger to call. bundleid (str, optional): Bundle ID of workflow trigger belongs to. arg (str, optional): Argument to pass to trigger. """ if not bundleid: bundleid = os.getenv('alfred_workflow_bundleid') if arg: arg = 'with argument "{}"'.format(applescriptify(arg)) else: arg = '' script = AS_TRIGGER.format(name=name, bundleid=bundleid, arg=arg) run_applescript(script)
Example #7
Source File: task_configuration.py From aws-ops-automator with Apache License 2.0 | 6 votes |
def create_task_config_objects(self, config_item): # get the class that implements the action and test if there is a static method for creating templates action_class = actions.get_action_class(config_item[configuration.CONFIG_ACTION_NAME]) create_task_objects_method = getattr(action_class, "create_task_config_objects", None) # if the method exists then validate the parameters using the business logic for that class bucket = os.getenv(configuration.ENV_CONFIG_BUCKET) prefix = "{}/{}/{}/".format(configuration.TASKS_OBJECTS, config_item[configuration.CONFIG_ACTION_NAME], config_item[configuration.CONFIG_TASK_NAME]) task_name = config_item[configuration.CONFIG_TASK_NAME] try: if create_task_objects_method is not None: cfg = self.get_parameters(config_item) objects = create_task_objects_method(cfg) if objects is not None: s3 = boto3.client("s3") for t in objects: s3.put_object(Bucket=bucket, Key=prefix + t, Body=objects[t]) self._logger.info("Created config object {}/{} in bucket {} for task {}", prefix, t, bucket, task_name) except Exception as ex: self._logger.error(ERR_CREATING_TASK_OBJECT, task_name, bucket, prefix, ex)
Example #8
Source File: mkl_fft.py From FRIDA with MIT License | 6 votes |
def load_libmkl(): if os.name == 'posix': try: lib_mkl = os.getenv('LIBMKL') return _ctypes.cdll.LoadLibrary(lib_mkl) except: pass try: return _ctypes.cdll.LoadLibrary("libmkl_rt.dylib") except: raise ValueError('MKL Library not found') else: try: return _ctypes.cdll.LoadLibrary("mk2_rt.dll") except: raise ValueError('MKL Library not found')
Example #9
Source File: setup.py From mmdetection with Apache License 2.0 | 6 votes |
def make_cuda_ext(name, module, sources, sources_cuda=[]): define_macros = [] extra_compile_args = {'cxx': []} if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1': define_macros += [('WITH_CUDA', None)] extension = CUDAExtension extra_compile_args['nvcc'] = [ '-D__CUDA_NO_HALF_OPERATORS__', '-D__CUDA_NO_HALF_CONVERSIONS__', '-D__CUDA_NO_HALF2_OPERATORS__', ] sources += sources_cuda else: print(f'Compiling {name} without CUDA') extension = CppExtension # raise EnvironmentError('CUDA is required to compile MMDetection!') return extension( name=f'{module}.{name}', sources=[os.path.join(*module.split('.'), p) for p in sources], define_macros=define_macros, extra_compile_args=extra_compile_args)
Example #10
Source File: action_base.py From aws-ops-automator with Apache License 2.0 | 6 votes |
def get_action_session(self, account, param_name=None, logger=None): self._logger_.debug("Getting action session for account \"{}\", task is \"{}\", parameter is \"{}\"", account, self._task_, param_name) try: role_name = self.get(param_name, None) if role_name is None: role_name = self.get(handlers.TASK_ROLE, None) if role_name is None: if account == os.getenv(handlers.ENV_OPS_AUTOMATOR_ACCOUNT): role_name = None else: role_name = handlers.default_rolename_for_stack() role_arn = handlers.ARN_ROLE_TEMPLATE.format(account, role_name) if role_name is not None else None self._logger_.debug("Role arn is \"{}\"", role_arn) return services.get_session(role_arn=role_arn, logger=logger) except Exception as ex: if logger is not None: logger.error(handlers.ERR_CREATING_SESSION, ex) return None
Example #11
Source File: run_checks.py From OpenFermion-Cirq with Apache License 2.0 | 6 votes |
def parse_args(): args = sys.argv verbose = '--verbose' in args only = [e.split('--only=')[1] for e in args if e.startswith('--only=')] checks = all_checks.ALL_CHECKS if only: checks = [e for e in checks if e.command_line_switch() in only] if len(checks) != len(only): print('Bad --only argument. Allowed values {!r}.'.format( [e.command_line_switch() for e in all_checks.ALL_CHECKS]), file=sys.stderr) sys.exit(1) checks = topologically_sorted_checks_with_deps(checks) positionals = [arg for arg in args if not arg.startswith('-')] pull_request_number = None if len(positionals) < 2 else int(positionals[1]) access_token = None if len(positionals) < 3 else int(positionals[2]) if access_token is None: access_token = os.getenv('CIRQ_GITHUB_ACCESS_TOKEN') return pull_request_number, access_token, verbose, checks
Example #12
Source File: issues_topic.py From aws-ops-automator with Apache License 2.0 | 6 votes |
def publish(self, level, msg, ext_info): sns_arn = os.getenv(ENV_SNS_ISSUE_TOPIC, None) if sns_arn is not None: message = { "log-group": self._loggroup, "log-stream": self._logstream, "level": level, "message": msg } if ext_info not in [None, {}]: for i in ext_info: message[i.lower()] = ext_info[i] topic_msg = safe_json({"default": safe_json(message, indent=3), "lambda": message}) resp = self.sns_client.publish_with_retries(TopicArn=sns_arn, Message=topic_msg, MessageStructure="json") print(resp)
Example #13
Source File: logger.py From lirpg with MIT License | 6 votes |
def configure(dir=None, format_strs=None): if dir is None: dir = os.getenv('OPENAI_LOGDIR') if dir is None: dir = osp.join(tempfile.gettempdir(), datetime.datetime.now().strftime("openai-%Y-%m-%d-%H-%M-%S-%f")) assert isinstance(dir, str) os.makedirs(dir, exist_ok=True) if format_strs is None: strs = os.getenv('OPENAI_LOG_FORMAT') format_strs = strs.split(',') if strs else LOG_OUTPUT_FORMATS output_formats = [make_output_format(f, dir) for f in format_strs] Logger.CURRENT = Logger(dir=dir, output_formats=output_formats) log('Logging to %s'%dir)
Example #14
Source File: mpi_fork.py From lirpg with MIT License | 6 votes |
def mpi_fork(n, bind_to_core=False): """Re-launches the current script with workers Returns "parent" for original parent, "child" for MPI children """ if n<=1: return "child" if os.getenv("IN_MPI") is None: env = os.environ.copy() env.update( MKL_NUM_THREADS="1", OMP_NUM_THREADS="1", IN_MPI="1" ) args = ["mpirun", "-np", str(n)] if bind_to_core: args += ["-bind-to", "core"] args += [sys.executable] + sys.argv subprocess.check_call(args, env=env) return "parent" else: return "child"
Example #15
Source File: osdriver.py From multibootusb with GNU General Public License v2.0 | 6 votes |
def gpt_device(self, dev_name): disk_dev = self.physical_disk(dev_name) cmd = ['parted', disk_dev, '-s', 'print'] with open(os.devnull) as devnull: p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=devnull) _cmd_out, _err_out = p.communicate() p.wait() if p.returncode != 0: lang = os.getenv('LANG') encoding = lang.rsplit('.')[-1] if lang else 'utf-8' raise RuntimeError(str(_err_out, encoding)) subprocess.check_call(['partprobe', disk_dev]) if b'msdos' in _cmd_out: return False if b'gpt' in _cmd_out: return True raise RuntimeError("Disk '%s' is uninitialized and not usable." % disk_dev)
Example #16
Source File: model.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
def _update_params_on_kvstore_nccl(param_arrays, grad_arrays, kvstore, param_names): """Perform update of param_arrays from grad_arrays on NCCL kvstore.""" valid_indices = [index for index, grad_list in enumerate(grad_arrays) if grad_list[0] is not None] valid_grad_arrays = [grad_arrays[i] for i in valid_indices] valid_param_arrays = [param_arrays[i] for i in valid_indices] valid_param_names = [param_names[i] for i in valid_indices] size = len(valid_grad_arrays) start = 0 # Use aggregation by default only with NCCL default_batch = '16' batch = int(os.getenv('MXNET_UPDATE_AGGREGATION_SIZE', default_batch)) while start < size: end = start + batch if start + batch < size else size # push gradient, priority is negative index kvstore.push(valid_param_names[start:end], valid_grad_arrays[start:end], priority=-start) # pull back the weights kvstore.pull(valid_param_names[start:end], valid_param_arrays[start:end], priority=-start) start = end
Example #17
Source File: anonymous_metrics.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def send_metrics_data(metrics_data, logger): url = os.getenv(metrics.ENV_METRICS_URL, None) if url is None: logger.warning(WARN_ENV_METRICS_URL_NOT_SET, metrics.ENV_METRICS_URL) return solution_id = os.getenv(metrics.ENV_SOLUTION_ID, None) if solution_id is None: logger.warning(WARN_SOLUTION_ID_NOT_SET) return data_dict = { "TimeStamp": str(datetime.utcnow().isoformat()), "UUID": str(uuid.uuid4()), "Data": metrics_data, "Solution": solution_id, } data_json = safe_json(data_dict, indent=3) logger.info(INF_METRICS_DATA, data_json) headers = { 'content-type': 'application/json', "content-length": str(len(data_json)) } try: response = requests.post(url, data=data_json, headers=headers) response.raise_for_status() logger.info(INF_METRICS_DATA_SENT, response.status_code, response.text) except Exception as exc: logger.info(INF_SENDING_METRICS_FAILED, str(exc))
Example #18
Source File: utils.py From indras_net with GNU General Public License v3.0 | 5 votes |
def get_prop_path(model_name, model_dir="models"): ihome = os.getenv("INDRA_HOME", " ") return ihome + "/" + model_dir + "/props/" + model_name + ".props.json"
Example #19
Source File: task_configuration.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def _event_bus_permissions_sid_prefix(): return "ops-automator-{}-{}-".format(os.getenv(handlers.ENV_STACK_NAME).lower(), services.get_session().region_name)
Example #20
Source File: task_tracking_table.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def account(self): return os.getenv(handlers.ENV_OPS_AUTOMATOR_ACCOUNT) # noinspection PyDictCreation
Example #21
Source File: helpers.py From quart with MIT License | 5 votes |
def get_env(default: Optional[str] = "production") -> str: """Reads QUART_ENV environment variable to determine in which environment the app is running on. Defaults to 'production' when unset. """ return os.getenv("QUART_ENV", default)
Example #22
Source File: helpers.py From quart with MIT License | 5 votes |
def get_debug_flag() -> bool: """ Reads QUART_DEBUG environment variable to determine whether to run the app in debug mode. If unset, and development mode has been configured, it will be enabled automatically. """ value = os.getenv("QUART_DEBUG", None) if value is None: return "development" == get_env() return value.lower() not in {"0", "false", "no"}
Example #23
Source File: anonymous_metrics.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def allow_send_metrics(): """ Tests if anonymous metrics can be send :return: True if metrics can be send """ return str(os.getenv(metrics.ENV_SEND_METRICS, "false")).lower() == "true"
Example #24
Source File: main.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def load_models(): cdw = os.getcwd() models = os.path.join(cdw, "models") aws_data_path = os.getenv("AWS_DATA_PATH", None) if aws_data_path is not None: aws_data_path = ":".join([aws_data_path, models]) else: aws_data_path = models os.environ["AWS_DATA_PATH"] = aws_data_path
Example #25
Source File: main.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def lambda_handler(event, context): dt = datetime.utcnow() log_stream_name = LOG_STREAM.format("OpsAutomatorMain", dt.year, dt.month, dt.day) with outputs.queued_logger.QueuedLogger(logstream=log_stream_name, context=context, buffersize=20) as logger: for handler_name in handlers.all_handlers(): try: if not handlers.get_class_for_handler(handler_name).is_handling_request(event, context): continue except Exception as ex: logger.error(ERR_IS_HANDLING, handler_name, safe_json(event, indent=2), ex) break if context is not None and os.getenv(ENV_DEBUG_MAIN_EVENT_HANDLER, "false").lower() == "true": print(("Handler is {}".format(handler_name))) print(("Event is {}".format(safe_json(event, indent=3)))) handler = handlers.create_handler(handler_name, event, context) try: logger.debug(DEBUG_HANDLER_INFO, handler_name) result = handler.handle_request() return safe_dict(result) except Exception as e: logger.error(ERR_HANDLING_REQUEST, safe_json(event, indent=2), handler_name, e, full_stack()) finally: if len(boto_retry.statistics) > 0: logger.info(MSG_BOTO_STATS, safe_json(boto_retry.statistics, indent=3)) boto_retry.clear_statistics() return else: logger.debug(MSG_NO_REQUEST_HANDLER, safe_json(event, indent=2))
Example #26
Source File: task_tracking_table.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def __init__(self, context=None, logger=None): """ Initializes the instance """ self._table = None self._client = None self._new_action_items = [] self._context = context self._logger = logger self._s3_client = None self._account = None self._run_local = handlers.running_local(self._context) self._resource_encryption_key = os.getenv(handlers.ENV_RESOURCE_ENCRYPTION_KEY, "") self._kms_client = None
Example #27
Source File: report_output_writer.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def write(self, data, key): s3_client = get_client_with_retries("s3", ["put_object"], context=self._context, logger=self._logger) s3_client.put_object_with_retries(Bucket=os.getenv(ENV_REPORT_BUCKET), Key=key, Body=data)
Example #28
Source File: queued_logger.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def __init__(self, logstream, context, loggroup=None, buffersize=50, use_retries=True, debug=False): def get_loggroup(lambda_context): group = os.getenv(ENV_LOG_GROUP, None) if group is None: if lambda_context is None: return None group = lambda_context.log_group_name return group self._logstream = logstream self._buffer_size = min(buffersize, 10000) self._context = context self._buffer = [] self._debug = debug self._cached_size = 0 self._client = None self._retries = use_retries self._loggroup = loggroup if loggroup is not None else get_loggroup(self._context) self._next_log_token = None self.issues_topic = IssuesTopic(log_group=self._loggroup, log_stream=self._logstream, context=context) self._trigger_table = os.getenv(ENV_CLOUDWATCH_TRIGGER_TABLE) put_general_errors_and_warnings(error_count=0, warning_count=0) self._sqs_client = None self._dynamodb_client = None self._num = 0
Example #29
Source File: queued_logger.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def _emit(self, level, msg, extended_info, *args): self._num += 1 s = msg if len(args) == 0 else msg.format(*args) t = time.time() dt = datetime.fromtimestamp(t) s = LOG_FORMAT.format(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, str(dt.microsecond)[0:3], level, s) log_msg = s if extended_info not in [None, {}]: log_msg = "{}\n{}".format(s, json.dumps(extended_info, indent=3)) if self._trigger_table is None: print(log_msg) return log_msg if self._cached_size + (len(log_msg) + LOG_ENTRY_ADDITIONAL) > LOG_MAX_BATCH_SIZE: self.flush() self._cached_size += len(s) + LOG_ENTRY_ADDITIONAL if handlers.running_local(self._context) and str(os.getenv(ENV_SUPPRESS_LOG_STDOUT, False)).lower() != "true": print(("> " + log_msg)) self._buffer.append((int(t * 1000), log_msg, self._num)) if len(self._buffer) >= self._buffer_size: self.flush() return s
Example #30
Source File: task_metrics.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def __init__(self, dt=None, logger=None, context=None): """ Initializes instance of metrics wrapper :param dt: date and time of the metrics data (typically the scheduling moment) """ self._dt = dt if dt is not None else datetime.utcnow() self._metrics = [] self._context = context self._logger = logger self._stack = os.getenv(handlers.ENV_STACK_NAME) self._stack_level = os.getenv(handlers.ENV_CLOUDWATCH_METRICS) self._namespace = "{}:{}".format(TaskMetrics.NAMESPACE, self._stack) self._metrics_client = None