~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-05 13:57:30 UTC
  • mto: This revision was merged to the branch mainline in revision 1990.
  • Revision ID: john@arbash-meinel.com-20060905135730-d51221405aa03eb2
Create an osutils helper function for modifying the environment

Show diffs side-by-side

added added

removed removed

Lines of Context:
867
867
 
868
868
    return width
869
869
 
 
870
 
870
871
def supports_executable():
871
872
    return sys.platform != "win32"
872
873
 
873
874
 
 
875
def set_or_unset_env(env_variable, value):
 
876
    """Modify the environment, setting or removing the env_variable.
 
877
 
 
878
    :param env_variable: The environment variable in question
 
879
    :param value: The value to set the environment to. If None, then
 
880
        the variable will be removed.
 
881
    :return: The original value of the environment variable.
 
882
    """
 
883
    orig_val = os.environ.get(env_variable)
 
884
    if value is None:
 
885
        if orig_val is not None:
 
886
            del os.environ[env_variable]
 
887
    else:
 
888
        if isinstance(value, unicode):
 
889
            value = value.encode(bzrlib.user_encoding)
 
890
        os.environ[env_variable] = value
 
891
    return orig_val
 
892
 
 
893
 
874
894
_validWin32PathRE = re.compile(r'^([A-Za-z]:[/\\])?[^:<>*"?\|]*$')
875
895
 
876
896