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