Salome HOME
fix #10458
[tools/sat.git] / src / fileEnviron.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2013  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import pprint as PP
21 import src.debug as DBG
22
23 bat_header="""@echo off
24
25 rem The following variables are used only in case of a sat package
26 set out_dir_Path=%~dp0
27 set PRODUCT_OUT_DIR=%out_dir_Path%
28 set prereq_install_Path=%out_dir_Path%\PREREQUISITES\INSTALL
29 set prereq_build_Path=%out_dir_Path%\PREREQUISITES\BUILD
30 """
31
32
33 bash_header="""#!/bin/bash
34 ##########################################################################
35 #
36 #### cleandup ###
37 # cleanup a path (first parameter) from duplicated entries;
38 # second parameter is the separator
39 cleandup() {
40 out_var=`echo $1 | awk -v sep=$2 '{                      \\
41      na = split($1,a,sep);                               \\
42      k=0;                                                \\
43      for(i=0;i<=na;i++) {                                \\
44        found=0;                                          \\
45        for(j=0;j<k;j++) {                                \\
46          if(a[i]==aa[j])                                 \\
47          {                                               \\
48            found=1;                                      \\
49            break;                                        \\
50          };                                              \\
51        };                                                \\
52        if(found==0) {                                    \\
53          aa[k++]=a[i];                                   \\
54        };                                                \\
55      };                                                  \\
56      ORS=sep;                                            \\
57      for(i=0;i<k;i++) {                                  \\
58        print aa[i];                                      \\
59      }                                                   \\
60    }' | sed -e 's|\\(.*\\)$1|\\1|g' -e 's|^[:;]||' -e 's|[:;]$||'`
61 echo $out_var
62 }
63 ### clean ###
64 clean ()
65 {
66 xenv=`printenv $1`
67 out_var=`cleandup $xenv $2`
68 export $1=$out_var
69 }
70
71 # The 3 following variables are used only in case of a sat package
72 export out_dir_Path=$(cd $(dirname ${BASH_SOURCE[0]});pwd)
73 export PRODUCT_OUT_DIR=${out_dir_Path}
74 export PRODUCT_ROOT_DIR=${PRODUCT_OUT_DIR}
75
76 ###########################################################################
77 """
78
79 cfg_header='''[SALOME Configuration]
80 '''
81
82 Launcher_header='''# a generated SALOME Configuration file using python syntax
83 '''
84
85 def get_file_environ(output, shell, environ=None):
86     """Instantiate correct FileEnvironment sub-class.
87     
88     :param output file: the output file stream.
89     :param shell str: the type of shell syntax to use.
90     :param environ dict: a potential additional environment.
91     """
92     if shell == "bash":
93         return BashFileEnviron(output, environ)
94     if shell == "bat":
95         return BatFileEnviron(output, environ)
96     if shell == "cfgForPy":
97         return LauncherFileEnviron(output, environ)
98     if shell == "cfg":
99         return ContextFileEnviron(output, environ)
100     raise Exception("FileEnviron: Unknown shell = %s" % shell)
101
102 class FileEnviron(object):
103     """Base class for shell environment
104     """
105     def __init__(self, output, environ=None):
106         """Initialization
107         
108         :param output file: the output file stream.
109         :param environ dict: a potential additional environment.
110         """
111         self._do_init(output, environ)
112
113     def __repr__(self):
114         """easy non exhaustive quick resume for debug print"""
115         res = {
116           "output" : self.output,
117           "environ" : self.environ,
118         }
119         return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res))
120         
121
122     def _do_init(self, output, environ=None):
123         """Initialization
124         
125         :param output file: the output file stream.
126         :param environ dict: a potential additional environment.
127         """
128         self.output = output
129         self.toclean = []
130         if environ is not None:
131             #if str(type(environ)) == "<type 'instance'>":
132             if id(environ) == id(os.environ):
133                DBG.tofix("set %s environ as python os.environ, are you sure it is safe ?" % self.__class__.__name__, True)
134             self.environ = environ
135         else:
136             DBG.tofix("set %s environ as COPY of python os.environ, are you sure it is safe ?" % self.__class__.__name__, True)
137             self.environ = dict(os.environ) #make a copy cvw 180320
138
139     def add_line(self, number):
140         """Add some empty lines in the shell file
141         
142         :param number int: the number of lines to add
143         """
144         self.output.write("\n" * number)
145
146     def add_comment(self, comment):
147         """Add a comment in the shell file
148         
149         :param comment str: the comment to add
150         """
151         self.output.write("# %s\n" % comment)
152
153     def add_echo(self, text):
154         """Add a "echo" in the shell file
155         
156         :param text str: the text to echo
157         """
158         self.output.write('echo %s"\n' % text)
159
160     def add_warning(self, warning):
161         """Add a warning "echo" in the shell file
162         
163         :param warning str: the text to echo
164         """
165         self.output.write('echo "WARNING %s"\n' % warning)
166
167     def append_value(self, key, value, sep=os.pathsep):
168         '''append value to key using sep
169         
170         :param key str: the environment variable to append
171         :param value str: the value to append to key
172         :param sep str: the separator string
173         '''
174         self.set(key, self.get(key) + sep + value)
175         if (key, sep) not in self.toclean:
176             self.toclean.append((key, sep))
177
178     def append(self, key, value, sep=os.pathsep):
179         '''Same as append_value but the value argument can be a list
180         
181         :param key str: the environment variable to append
182         :param value str or list: the value(s) to append to key
183         :param sep str: the separator string
184         '''
185         if isinstance(value, list):
186             self.append_value(key, sep.join(value), sep)
187         else:
188             self.append_value(key, value, sep)
189
190     def prepend_value(self, key, value, sep=os.pathsep):
191         '''prepend value to key using sep
192         
193         :param key str: the environment variable to prepend
194         :param value str: the value to prepend to key
195         :param sep str: the separator string
196         '''
197         self.set(key, value + sep + self.get(key))
198         if (key, sep) not in self.toclean:
199             self.toclean.append((key, sep))
200
201     def prepend(self, key, value, sep=os.pathsep):
202         '''Same as prepend_value but the value argument can be a list
203         
204         :param key str: the environment variable to prepend
205         :param value str or list: the value(s) to prepend to key
206         :param sep str: the separator string
207         '''
208         if isinstance(value, list):
209             self.prepend_value(key, sep.join(value), sep)
210         else:
211             self.prepend_value(key, value, sep)
212
213     def is_defined(self, key):
214         '''Check if the key exists in the environment
215         
216         :param key str: the environment variable to check
217         '''
218         return (key in self.environ)
219
220     def set(self, key, value):
221         '''Set the environment variable "key" to value "value"
222         
223         :param key str: the environment variable to set
224         :param value str: the value
225         '''
226         raise NotImplementedError("set is not implement for this shell!")
227
228     def get(self, key):
229         '''Get the value of the environment variable "key"
230         
231         :param key str: the environment variable
232         '''
233         return '${%s}' % key
234
235     def command_value(self, key, command):
236         '''Get the value given by the system command "command" 
237            and put it in the environment variable key.
238            Has to be overwritten in the derived classes
239            This can be seen as a virtual method
240         
241         :param key str: the environment variable
242         :param command str: the command to execute
243         '''
244         raise NotImplementedError("command_value is not implement "
245                                   "for this shell!")
246
247     def finish(self, required=True):
248         """Add a final instruction in the out file (in case of file generation)
249         
250         :param required bool: Do nothing if required is False
251         """
252         for (key, sep) in self.toclean:
253             if sep != ' ':
254                 self.output.write('clean %s "%s"\n' % (key, sep))
255
256 class BashFileEnviron(FileEnviron):
257     """Class for bash shell.
258     """
259     def __init__(self, output, environ=None):
260         """Initialization
261         
262         :param output file: the output file stream.
263         :param environ dict: a potential additional environment.
264         """
265         self._do_init(output, environ)
266         self.output.write(bash_header)
267
268     def set(self, key, value):
269         '''Set the environment variable "key" to value "value"
270         
271         :param key str: the environment variable to set
272         :param value str: the value
273         '''
274         self.output.write('export %s="%s"\n' % (key, value))
275         self.environ[key] = value
276
277     def command_value(self, key, command):
278         '''Get the value given by the system command "command" 
279            and put it in the environment variable key.
280            Has to be overwritten in the derived classes
281            This can be seen as a virtual method
282         
283         :param key str: the environment variable
284         :param command str: the command to execute
285         '''
286         self.output.write('export %s=$(%s)\n' % (key, command))
287
288     def finish(self, required=True):
289         """Add a final instruction in the out file (in case of file generation)
290         
291         :param required bool: Do nothing if required is False
292         """
293         if not required:
294             return
295         FileEnviron.finish(self, required)
296         
297 class BatFileEnviron(FileEnviron):
298     """for Windows batch shell.
299     """
300     def __init__(self, output, environ=None):
301         """Initialization
302         
303         :param output file: the output file stream.
304         :param environ dict: a potential additional environment.
305         """
306         self._do_init(output, environ)
307         self.output.write(bat_header)
308
309     def add_comment(self, comment):
310         """Add a comment in the shell file
311         
312         :param comment str: the comment to add
313         """
314         self.output.write("rem %s\n" % comment)
315     
316     def get(self, key):
317         '''Get the value of the environment variable "key"
318         
319         :param key str: the environment variable
320         '''
321         return '%%%s%%' % key
322     
323     def set(self, key, value):
324         '''Set the environment variable "key" to value "value"
325         
326         :param key str: the environment variable to set
327         :param value str: the value
328         '''
329         self.output.write('set %s=%s\n' % (key, value))
330         self.environ[key] = value
331
332     def command_value(self, key, command):
333         '''Get the value given by the system command "command" 
334            and put it in the environment variable key.
335            Has to be overwritten in the derived classes
336            This can be seen as a virtual method
337         
338         :param key str: the environment variable
339         :param command str: the command to execute
340         '''
341         self.output.write('%s > tmp.txt\n' % (command))
342         self.output.write('set /p %s =< tmp.txt\n' % (key))
343
344     def finish(self, required=True):
345         """Add a final instruction in the out file (in case of file generation)
346            In the particular windows case, do nothing
347         
348         :param required bool: Do nothing if required is False
349         """
350         return
351
352 class ContextFileEnviron(FileEnviron):
353     """Class for a salome context configuration file.
354     """
355     def __init__(self, output, environ=None):
356         """Initialization
357         
358         :param output file: the output file stream.
359         :param environ dict: a potential additional environment.
360         """
361         self._do_init(output, environ)
362         self.output.write(cfg_header)
363
364     def set(self, key, value):
365         '''Set the environment variable "key" to value "value"
366         
367         :param key str: the environment variable to set
368         :param value str: the value
369         '''
370         self.output.write('%s="%s"\n' % (key, value))
371         self.environ[key] = value
372
373     def get(self, key):
374         '''Get the value of the environment variable "key"
375         
376         :param key str: the environment variable
377         '''
378         return '%({0})s'.format(key)
379
380     def command_value(self, key, command):
381         '''Get the value given by the system command "command" 
382            and put it in the environment variable key.
383            Has to be overwritten in the derived classes
384            This can be seen as a virtual method
385         
386         :param key str: the environment variable
387         :param command str: the command to execute
388         '''
389         raise NotImplementedError("command_value is not implement "
390                                   "for salome context files!")
391
392     def add_echo(self, text):
393         """Add a comment
394         
395         :param text str: the comment to add
396         """
397         self.add_comment(text)
398
399     def add_warning(self, warning):
400         """Add a warning
401         
402         :param text str: the warning to add
403         """
404         self.add_comment("WARNING %s"  % warning)
405
406     def prepend_value(self, key, value, sep=os.pathsep):
407         '''prepend value to key using sep
408         
409         :param key str: the environment variable to prepend
410         :param value str: the value to prepend to key
411         :param sep str: the separator string
412         '''
413         self.output.write('ADD_TO_%s: %s\n' % (key, value))
414
415     def append_value(self, key, value, sep=os.pathsep):
416         '''append value to key using sep
417         
418         :param key str: the environment variable to append
419         :param value str: the value to append to key
420         :param sep str: the separator string
421         '''
422         self.prepend_value(key, value)
423
424     def finish(self, required=True):
425         """Add a final instruction in the out file (in case of file generation)
426         
427         :param required bool: Do nothing if required is False
428         """
429         return
430
431 def special_path_separator(name):
432     """TCLLIBPATH, TKLIBPATH, PV_PLUGIN_PATH environments variables need
433        some exotic path separator.
434        This function gives the separator regarding the name of the variable
435        to append or prepend.
436        
437     :param name str: The name of the variable to find the separator
438     """
439     special_blanks_keys=["TCLLIBPATH", "TKLIBPATH"]
440     special_semicolon_keys=["PV_PLUGIN_PATH"]
441     res=os.pathsep
442     if name in special_blanks_keys: res=" "
443     if name in special_semicolon_keys: res=";"
444     return res
445
446 class LauncherFileEnviron:
447     """Class to generate a launcher file script 
448        (in python syntax) SalomeContext API
449     """
450     def __init__(self, output, environ=None):
451         """Initialization
452         
453         :param output file: the output file stream.
454         :param environ dict: a potential additional environment.
455         """
456         self.output = output
457         self.toclean = []
458         if environ is not None:
459             self.environ = environ
460         else:
461             self.environ = os.environ
462         # Initialize some variables
463         if not "PATH" in self.environ.keys():
464             self.environ["PATH"]=""
465         if not "LD_LIBRARY_PATH" in self.environ.keys():
466             self.environ["LD_LIBRARY_PATH"]=""
467         if not "PYTHONPATH" in self.environ.keys():
468             self.environ["PYTHONPATH"]=""
469         if not "TCLLIBPATH" in self.environ.keys():
470             self.environ["TCLLIBPATH"]=""
471         if not "TKLIBPATH" in self.environ.keys():
472             self.environ["TKLIBPATH"]=""
473
474         # four whitespaces for first indentation in a python script
475         self.indent="    "
476         self.prefix="context."
477         self.setVarEnv="setVariable"
478         
479         self.begin=self.indent+self.prefix
480         self.output.write(Launcher_header)
481         self.specialKeys={"PATH": "Path",
482                           "LD_LIBRARY_PATH": "LdLibraryPath",
483                           "PYTHONPATH": "PythonPath"}
484
485     def change_to_launcher(self, value):
486         """
487         """
488         res=value
489         return res
490
491     def add_line(self, number):
492         """Add some empty lines in the launcher file
493         
494         :param number int: the number of lines to add
495         """
496         self.output.write("\n" * number)
497
498     def add_echo(self, text):
499         """Add a comment
500         
501         :param text str: the comment to add
502         """
503         self.output.write('# %s"\n' % text)
504
505     def add_warning(self, warning):
506         """Add a warning
507         
508         :param text str: the warning to add
509         """
510         self.output.write('# "WARNING %s"\n' % warning)
511
512     def append_value(self, key, value, sep=":"):
513         '''append value to key using sep
514         
515         :param key str: the environment variable to append
516         :param value str: the value to append to key
517         :param sep str: the separator string
518         '''
519         if self.is_defined(key) :
520             self.add(key, value)
521         else :
522             self.set(key, value)
523
524     def append(self, key, value, sep=":"):
525         '''Same as append_value but the value argument can be a list
526         
527         :param key str: the environment variable to append
528         :param value str or list: the value(s) to append to key
529         :param sep str: the separator string
530         '''
531         if isinstance(value, list):
532             self.append_value(key, sep.join(value), sep)
533         else:
534             self.append_value(key, value, sep)
535
536     def prepend_value(self, key, value, sep=":"):
537         '''prepend value to key using sep
538         
539         :param key str: the environment variable to prepend
540         :param value str: the value to prepend to key
541         :param sep str: the separator string
542         '''
543         if self.is_defined(key) :
544             self.add(key, value)
545         else :
546             self.set(key, value)
547
548     def prepend(self, key, value, sep=":"):
549         '''Same as prepend_value but the value argument can be a list
550         
551         :param key str: the environment variable to prepend
552         :param value str or list: the value(s) to prepend to key
553         :param sep str: the separator string
554         '''
555         if isinstance(value, list):
556             self.prepend_value(key, sep.join(value), sep)
557         else:
558             self.prepend_value(key, value, sep)
559
560     def is_defined(self, key):
561         '''Check if the key exists in the environment
562         
563         :param key str: the environment variable to check
564         '''
565         return key in self.environ.keys()
566
567     def get(self, key):
568         '''Get the value of the environment variable "key"
569         
570         :param key str: the environment variable
571         '''
572         return '${%s}' % key
573
574     def set(self, key, value):
575         '''Set the environment variable "key" to value "value"
576         
577         :param key str: the environment variable to set
578         :param value str: the value
579         '''
580         self.output.write(self.begin+self.setVarEnv+
581                           '(r"%s", r"%s", overwrite=True)\n' % 
582                           (key, self.change_to_launcher(value)))
583         self.environ[key] = value
584     
585     def add(self, key, value):
586         '''prepend value to key using sep
587         
588         :param key str: the environment variable to prepend
589         :param value str: the value to prepend to key
590         '''     
591         if key in self.specialKeys.keys():
592             self.output.write(self.begin+'addTo%s(r"%s")\n' % 
593                               (self.specialKeys[key],
594                                self.change_to_launcher(value)))
595             self.environ[key]+=":"+value
596             return
597         sep=special_path_separator(key)
598         self.output.write(self.indent+
599                           '#temporary solution!!! have to be defined in API a '
600                           '?dangerous? addToSpecial(r"%s", r"%s")\n' % 
601                           (key, value))
602         #pathsep not precised because do not know future os launch?
603         self.output.write(self.begin+'addToSpecial(r"%s", r"%s")\n' 
604                           % (key, self.change_to_launcher(value)))
605         self.environ[key]+=sep+value #here yes we know os for current execution
606
607     def command_value(self, key, command):
608         '''Get the value given by the system command "command" 
609            and put it in the environment variable key.
610         
611         :param key str: the environment variable
612         :param command str: the command to execute
613         '''
614         self.output.write(self.indent+'#`%s`\n' % command)
615
616         import shlex, subprocess
617         args = shlex.split(command)
618         res=subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
619         out, __ = res.communicate()
620         self.output.write(self.begin+
621                           self.setVarEnv+
622                           '(r"%s", r"%s", overwrite=True)\n' % (key, out))
623
624     def add_comment(self, comment):
625         # Special comment in case of the distène licence
626         if comment=="DISTENE license":
627             self.output.write(self.indent+
628                               "#"+
629                               self.prefix+
630                               self.setVarEnv+
631                               '(r"%s", r"%s", overwrite=True)\n' % 
632                               ('DISTENE_LICENSE_FILE', 
633                                self.change_to_launcher(
634                                             'Use global envvar: DLIM8VAR')))
635             self.output.write(self.indent+
636                               "#"+
637                               self.prefix+
638                               self.setVarEnv+
639                               '(r"%s", r"%s", overwrite=True)\n' % 
640                               ('DLIM8VAR', 
641                                self.change_to_launcher(
642                                                 '<your licence>')))
643             return
644         if "setting environ for" in comment:
645             self.output.write(self.indent+"#[%s]\n" % 
646                               comment.split("setting environ for ")[1])
647             return
648
649         self.output.write(self.indent+"# %s\n" % comment)
650
651     def finish(self, required=True):
652         """Add a final instruction in the out file (in case of file generation)
653            In the particular launcher case, do nothing
654         
655         :param required bool: Do nothing if required is False
656         """
657         return
658
659 class ScreenEnviron(FileEnviron):
660     def __init__(self, output, environ=None):
661         self._do_init(output, environ)
662         self.defined = {}
663
664     def add_line(self, number):
665         pass
666
667     def add_comment(self, comment):
668         pass
669
670     def add_echo(self, text):
671         pass
672
673     def add_warning(self, warning):
674         pass
675
676     def write(self, command, name, value, sign="="):
677         import src
678         self.output.write("  %s%s %s %s %s\n" % \
679             (src.printcolors.printcLabel(command),
680              " " * (12 - len(command)),
681              src.printcolors.printcInfo(name), sign, value))
682
683     def is_defined(self, name):
684         return self.defined.has_key(name)
685
686     def get(self, name):
687         return "${%s}" % name
688
689     def set(self, name, value):
690         self.write("set", name, value)
691         self.defined[name] = value
692
693     def prepend(self, name, value, sep=":"):
694         if isinstance(value, list):
695             value = sep.join(value)
696         value = value + sep + self.get(name)
697         self.write("prepend", name, value)
698
699     def append(self, name, value, sep=":"):
700         if isinstance(value, list):
701             value = sep.join(value)
702         value = self.get(name) + sep + value
703         self.write("append", name, value)
704
705     def command_value(self, key, command):
706         pass
707
708     def run_env_script(self, module, script):
709         self.write("load", script, "", sign="")
710
711 # The SALOME launcher template 
712 withProfile =  """#! /usr/bin/env python
713
714 ################################################################
715 # WARNING: this file is automatically generated by SalomeTools #
716 # WARNING: and so could be overwritten at any time.            #
717 ################################################################
718
719 import os
720 import sys
721
722
723 # Add the pwdPath to able to run the launcher after unpacking a package
724 # Used only in case of a salomeTools package
725 out_dir_Path=os.path.abspath(os.path.dirname(__file__))
726
727 # Preliminary work to initialize path to SALOME Python modules
728 def __initialize():
729
730   sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]
731   os.environ['ABSOLUTE_APPLI_PATH'] = 'KERNEL_INSTALL_DIR'
732   
733   # define folder to store omniorb config (initially in virtual application folder)
734   try:
735     from salomeContextUtils import setOmniOrbUserPath
736     setOmniOrbUserPath()
737   except Exception, e:
738     print e
739     sys.exit(1)
740 # End of preliminary work
741
742 def main(args):
743   # Identify application path then locate configuration files
744   __initialize()
745
746   if args == ['--help']:
747     from salomeContext import usage
748     usage()
749     sys.exit(0)
750
751   #from salomeContextUtils import getConfigFileNames
752   #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True )
753   #if len(unexisting) > 0:
754   #  print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting)
755   #  sys.exit(1)
756
757   # Create a SalomeContext which parses configFileNames to initialize environment
758   try:
759     from salomeContext import SalomeContext, SalomeContextException
760     SalomeContext.addToSpecial=addToSpecial
761     context = SalomeContext(None)
762     
763     # Here set specific variables, if needed
764     # context.addToPath('mypath')
765     # context.addToLdLibraryPath('myldlibrarypath')
766     # context.addToPythonPath('mypythonpath')
767     # context.setVariable('myvarname', 'value')
768
769     # Logger level error
770     context.getLogger().setLevel(40)
771
772     context.setVariable(r"PRODUCT_ROOT_DIR", out_dir_Path, overwrite=True)
773     # here your local standalone environment
774
775     # Start SALOME, parsing command line arguments
776     context.runSalome(args)
777     #print 'Thank you for using SALOME!'
778
779     # Logger level info
780     context.getLogger().setLevel(20)
781
782   except SalomeContextException, e:
783     import logging
784     logging.getLogger("salome").error(e)
785     sys.exit(1)
786 #
787 def addToSpecial(self, name, value, pathSep=None):
788   "add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc..."
789   #http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm
790   #TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows.
791   if value == '':
792     return
793   
794   specialBlanksKeys=["TCLLIBPATH", "TKLIBPATH"]
795   specialSemicolonKeys=["PV_PLUGIN_PATH"]
796   res=os.pathsep
797   if name in specialBlanksKeys: res=" "
798   if name in specialSemicolonKeys: res=";"
799   
800   if pathSep==None:
801     sep=res
802   else:
803     sep=pathSep
804   value = os.path.expandvars(value) # expand environment variables
805   self.getLogger().debug("Add to %s: %s", name, value)
806   env = os.getenv(name, None)
807   if env is None:
808     os.environ[name] = value
809   else:
810     os.environ[name] = value + sep + env #explicitely or not special path separator ?whitespace, semicolon?
811
812 if __name__ == "__main__":
813   args = sys.argv[1:]
814   main(args)
815 #
816 """
817