6
6
#===============================================================================
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
20
22
prefix = os.path.dirname(os.path.dirname(homedir))
21
23
product = os.path.splitext(os.path.basename(sys.argv[0]))[0]
23
if os.name == 'posix':
26
runas = os.getenv('USERNAME',os.getenv('USER','.'))
25
29
runas = os.environ['SUDO_USER'] if os.geteuid() == 0 and 'SUDO_USER' in os.environ else pwd.getpwuid(os.geteuid()).pw_name
27
runas = os.environ['USERNAME']
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']),
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',]
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):
64
prefixini = [os.getenv('APPDATA','.'),]
65
elif not installed_host.lower() == 'none' or \
66
homedir.lower().startswith(host):
68
prefixini = [os.getenv('ALLUSERSPROFILE','.'),'Application Data',]
57
70
if os.path.exists(os.sep.join(prefixini+[homebase,basenameini])):
58
71
defaults['setup']['inifile'] = os.sep.join(prefixini+[homebase,basenameini])
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)))
467
with open(os.sep.join([working,'.lastupdate']),'w') as f:
468
f.write('%s\n'%('\n'.join(contents)))
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))
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))