~domy/corpusfiltergraph/old-main

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/cfgparser.py

  • Committer: tahoar
  • Date: 2012-10-26 14:59:20 UTC
  • Revision ID: svn-v4:bc069b21-dff4-4e29-a776-06a4e04bad4e::331
ChangesĀ supportingĀ DoMTĀ release

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#===============================================================================
7
7
 
8
8
#version:
9
 
#4.5.330 - updated getproductdefaults() for consistency with GUI
 
9
#4.5.331 - update getproductdefaults() to support new configuration locations
 
10
#          update runas = to support USERNAME and USER environment variables on Windows
 
11
#          update to save new config.ini to config.NEW-[datetime].conf supporting new GUI
10
12
 
11
13
import sys
12
14
import os
20
22
prefix = os.path.dirname(os.path.dirname(homedir))
21
23
product = os.path.splitext(os.path.basename(sys.argv[0]))[0]
22
24
 
23
 
if os.name == 'posix':
 
25
if os.name == 'nt':
 
26
        runas = os.getenv('USERNAME',os.getenv('USER','.'))
 
27
else:
24
28
        import pwd
25
29
        runas = os.environ['SUDO_USER'] if os.geteuid() == 0 and 'SUDO_USER' in os.environ else pwd.getpwuid(os.geteuid()).pw_name
26
 
else:
27
 
        runas = os.environ['USERNAME']
28
30
 
29
31
defaults = {
30
32
        'setup': {
31
 
                'version': u'4.5.330',
 
33
                'version': u'4.5.331',
32
34
                'product': product,
33
35
                'inifile': os.sep.join([homedir,''.join([product,'.ini'])]),
34
36
                'graphs': os.sep.join([homedir,'graphs']),
49
51
 
50
52
        basenameini = '%s.ini'%(product)
51
53
        prefixini = [prefix,'etc',]
52
 
        if os.name == 'nt' and homedir.startswith(os.sep.join([os.getenv('HOMEDRIVE','.'),os.getenv('HOMEPATH','.').strip(os.sep)])) or \
53
 
                homedir.startswith(os.sep.join(['Z:','home',os.getenv('USER','.')])): # special wine testing
54
 
                prefixini = [os.getenv('APPDATA','.'),]
55
 
        elif os.name == 'nt' and homedir.startswith(os.sep.join([os.getenv('ProgramFiles','.'),homebase])):
56
 
                prefixini = [os.getenv('ALLUSERSPROFILE','.'),'Application Data',]
 
54
        if os.name == 'nt':
 
55
                home = os.sep.join([os.getenv('HOMEDRIVE','.').strip(os.sep),os.getenv('HOMEPATH','.').strip(os.sep)]).lower()
 
56
                wine = os.sep.join(['z:','home',os.getenv('USERNAME',os.getenv('USER','.'))]).lower() # special wine testing
 
57
                host = os.sep.join([os.getenv('PROGRAMFILES','.'),homebase]).lower()
 
58
                installed_host = iniFileGet(os.sep.join([os.getenv('ALLUSERSPROFILE','.'),'Application Data',product,'status.ini']),'setup','installdir',value='None')
 
59
                installed_user = iniFileGet(os.sep.join([os.getenv('APPDATA','.'),product,'status.ini']),'setup','installdir',value='None')
 
60
                if not installed_user.lower() == 'none' or \
 
61
                        homedir.lower().startswith(home) or \
 
62
                        homedir.lower().startswith(wine):
 
63
                        # user installation
 
64
                        prefixini = [os.getenv('APPDATA','.'),]
 
65
                elif not installed_host.lower() == 'none' or \
 
66
                        homedir.lower().startswith(host):
 
67
                        # host installation
 
68
                        prefixini = [os.getenv('ALLUSERSPROFILE','.'),'Application Data',]
 
69
 
57
70
        if os.path.exists(os.sep.join(prefixini+[homebase,basenameini])):
58
71
                defaults['setup']['inifile'] = os.sep.join(prefixini+[homebase,basenameini])
59
72
 
450
463
        if (updates and not master_lastupdate == now[0]) or forcesetup:
451
464
                contents = sorted(['%s\t%s'%(path.replace('%s%s'%(working,os.sep),''),crc) for path,crc in updates.items()])
452
465
                contents.insert(0,newest[0])
453
 
                with open(os.sep.join([working,'.lastupdate']),'w') as f:
454
 
                        f.write('%s\n'%('\n'.join(contents)))
 
466
                try:
 
467
                        with open(os.sep.join([working,'.lastupdate']),'w') as f:
 
468
                                f.write('%s\n'%('\n'.join(contents)))
 
469
                except:
 
470
                        pass
455
471
 
456
472
def _makedefaultini(inputini,config):
457
473
        if not 'setup' in config.keys() or not 'inifile' in config['setup'].keys():
500
516
                                        if srccrc == dstcrc:
501
517
                                                updates[dstname] = dstcrc
502
518
                                        elif name == 'config.ini':
503
 
                                                shutil.copy2(srcname,'%s.NEW-%s%s'%(os.path.splitext(dstname)[0],datetime,os.path.splitext(dstname)[1]))
 
519
                                                altdestname = '%s.NEW-%s%s'%(os.path.splitext(dstname)[0],datetime,'.conf')
 
520
                                                shutil.copy2(srcname,altdestname)
504
521
#                                               updates[dstname] = str(cf.crc(srcname))
505
522
                                        else:
506
523
                                                if not dstname in lastupdates or not dstcrc == lastupdates[dstname]:
507
524
                                                        # unregistered working copy, or working copy changed. rename working copy before coping new master
508
 
                                                        shutil.move(dstname,'%s.WORKING-%s%s.bak'%(os.path.splitext(dstname)[0],datetime,os.path.splitext(dstname)[1]))
 
525
                                                        altdestname = '%s.WORKING-%s%s.bak'%(os.path.splitext(dstname)[0],datetime,os.path.splitext(dstname)[1])
 
526
                                                        shutil.move(dstname,altdestname)
509
527
                                                shutil.copy2(srcname,dstname)
510
528
                                                updates[dstname] = str(cf.crc(dstname))
511
529
                                else: