everything seems to work

This commit is contained in:
Mattias Andrée 2012-08-26 15:27:33 +02:00
parent 6b51b06e2d
commit 30306dae62

View file

@ -252,7 +252,7 @@ class Setup():
data = data.replace('/usr/share/ponysay/' + sharedir, conf[sharedir]) data = data.replace('/usr/share/ponysay/' + sharedir, conf[sharedir])
for sharefile in sharefiles: for sharefile in sharefiles:
data = data.replace('/usr/share/ponysay/' + sharefile[1], conf[sharefile[0]]) data = data.replace('/usr/share/ponysay/' + sharefile[1], conf[sharefile[0]])
data.replace('\nVERSION = \'dev\'', '\nVERSION = \'%s\'' % (PONYSAY_VERSION)) data = data.replace('\nVERSION = \'dev\'', '\nVERSION = \'%s\'' % (PONYSAY_VERSION))
fileout.write(data) fileout.write(data)
finally: finally:
@ -294,12 +294,17 @@ class Setup():
if ext is not None: if ext is not None:
compress('ponysay.info', 'ponysay.info.' + ext, ext) compress('ponysay.info', 'ponysay.info.' + ext, ext)
if conf['pdf-compression'] is not None:
ext = conf['pdf-compression']
if ext is not None:
compress('ponysay.pdf', 'ponysay.pdf.' + ext, ext)
for shell in [item[0] for item in shells]: for shell in [item[0] for item in shells]:
if conf[shell] is not None: if conf[shell] is not None:
src = 'completion/%s-completion.%s' % (shell, 'sh' if shell == 'bash' else shell) src = 'completion/%s-completion.%s' % (shell, 'sh' if shell == 'bash' else shell)
for command in commands: for command in commands:
if conf[shell] is not None: if conf[command] is not None:
dest = src + '.' + shell dest = src + '.' + command
(fileout, filein) = (None, None) (fileout, filein) = (None, None)
try: try:
fileout = open(dest, 'w+') fileout = open(dest, 'w+')
@ -335,6 +340,7 @@ class Setup():
finally: finally:
if ponymap is not None: if ponymap is not None:
ponymap.close() ponymap.close()
print()
''' '''
@ -357,11 +363,13 @@ class Setup():
os.chmod(dests[0], 0o755) os.chmod(dests[0], 0o755)
if conf['shared-cache'] is not None: if conf['shared-cache'] is not None:
dir = conf['shared-cache'] dir = conf['shared-cache']
pdir = dir[:rfind('/') + 1] if not os.path.exists(dir):
pdir = dir[:dir.rfind('/') + 1]
if not os.path.exists(pdir):
print('Creating intermediate-level directories needed for ' + dir) print('Creating intermediate-level directories needed for ' + dir)
os.makedirs(pdir) os.makedirs(pdir)
print('Creating directory ' + dir + ' with mode mask 777') print('Creating directory ' + dir + ' with mode mask 777')
os.makedir(dir, 0o777) os.mkdir(dir, 0o777)
for shell in [item[0] for item in shells]: for shell in [item[0] for item in shells]:
if conf[shell] is not None: if conf[shell] is not None:
for command in commands: for command in commands:
@ -404,7 +412,7 @@ class Setup():
dest = '%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression']) dest = '%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression'])
dests.append(dest) dests.append(dest)
self.cp(False, src, dests) self.cp(False, src, dests)
for dir in sharefiles: for dir in sharedirs:
if conf[dir[0]] is not None: if conf[dir[0]] is not None:
self.cp(True, dir[0], [conf[dir[0]]]) self.cp(True, dir[0], [conf[dir[0]]])
for file in sharefiles: for file in sharefiles:
@ -412,6 +420,7 @@ class Setup():
self.cp(False, 'share/' + file[1], [conf[file[0]]]) self.cp(False, 'share/' + file[1], [conf[file[0]]])
for file in miscfiles: for file in miscfiles:
self.cp(False, file[0], [conf[file[0]]]) self.cp(False, file[0], [conf[file[0]]])
print()
''' '''
@ -420,7 +429,7 @@ class Setup():
def uninstall(self, conf): def uninstall(self, conf):
print('\033[1;34m::\033[39mUninstalling...\033[21m') print('\033[1;34m::\033[39mUninstalling...\033[21m')
(files, dirs, info) = ([], [], []) (files, dirs, infos) = ([], [], [])
for command in commands: for command in commands:
if conf[command] is not None: if conf[command] is not None:
@ -441,7 +450,7 @@ class Setup():
files.append(file) files.append(file)
if conf['info-install'] is not None: if conf['info-install'] is not None:
infos.append(file) infos.append(file)
for man in [item[0] for item in manpages]: ## TODO manpage languages for man in [item[0] for item in manpages]:
key = 'man-' + man key = 'man-' + man
section = conf['man-section-ponysay'] section = conf['man-section-ponysay']
if man is manpages[0]: sub = 'man' + section if man is manpages[0]: sub = 'man' + section
@ -450,7 +459,7 @@ class Setup():
for command in commands: for command in commands:
if conf[command] is not None: if conf[command] is not None:
files.append('%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression'])) files.append('%s/%s/%s.%s%s' % (conf[key], sub, command, section, '' if conf[key + '-compression'] is None else '.' + conf[key + '-compression']))
for dir in sharefiles: for dir in sharedirs:
if conf[dir[0]] is not None: if conf[dir[0]] is not None:
dirs.append(conf[dir[0]]) dirs.append(conf[dir[0]])
for file in sharefiles: for file in sharefiles:
@ -466,6 +475,7 @@ class Setup():
os.system(cmd) os.system(cmd)
self.removeLists(files, dirs) self.removeLists(files, dirs)
print()
''' '''
@ -486,6 +496,7 @@ class Setup():
#$(instdir)/lib/ponysay/pq4ps-list.pl #$(instdir)/lib/ponysay/pq4ps-list.pl
self.removeLists(files, dirs) self.removeLists(files, dirs)
print()
''' '''
@ -506,6 +517,7 @@ class Setup():
files.append('completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command)) files.append('completion/%s-completion.%s.%s' % (shell, 'sh' if shell == 'bash' else shell, command))
self.removeLists(files, dirs) self.removeLists(files, dirs)
print()
''' '''
@ -521,6 +533,7 @@ class Setup():
files.append('completion/%s-completion-think.%s' % (shell, 'sh' if shell == 'bash' else shell)) files.append('completion/%s-completion-think.%s' % (shell, 'sh' if shell == 'bash' else shell))
self.removeLists(files, dirs) self.removeLists(files, dirs)
print()
''' '''
@ -528,26 +541,26 @@ class Setup():
''' '''
def removeLists(self, files, dirs): def removeLists(self, files, dirs):
for file in files: for file in files:
if os.path.isfile(file): if os.path.isfile(file) or os.path.islink(file):
print('Unlinking file %s' % (file)) print('Unlinking file %s' % (file))
os.unlink(file) os.unlink(file)
dir = file dir = file
while True: while True:
dir = dir[:dir.rfind('/') + 1] dir = dir[:dir.rfind('/')]
if ('/ponysay/' in dir) and (len(os.listdir(dir)) == 0): if ('/ponysay/' in (dir + '/')) and (len(os.listdir(dir)) == 0):
print('Removing newly empty directory %s' % (file)) print('Removing newly empty directory %s' % (dir))
os.rmdir(dir) os.rmdir(dir)
else: else:
break; break;
for dir in dirs: for dir in dirs:
if os.path.isdir(dir): if os.path.isdir(dir) or os.path.islink(dir):
print('Cascadingly removing directory %s' % (dir)) print('Cascadingly removing directory %s' % (dir))
if os.path.islink(dir): os.unlink(dir) if os.path.islink(dir): os.unlink(dir)
else: shutil.rmtree(dir) else: shutil.rmtree(dir)
while True: while True:
dir = dir[:dir.rfind('/') + 1] dir = dir[:dir.rfind('/')]
if ('/ponysay/' in dir) and (len(os.listdir(dir)) == 0): if ('/ponysay/' in (dir + '/')) and (len(os.listdir(dir)) == 0):
print('Removing newly empty directory %s' % (file)) print('Removing newly empty directory %s' % (dir))
os.rmdir(dir) os.rmdir(dir)
else: else:
break; break;
@ -574,6 +587,8 @@ class Setup():
if self.linking != COPY: if self.linking != COPY:
for dest in destinations[1:]: for dest in destinations[1:]:
print('Creating symbolic link %s with target directory %s' % (dest, target)) print('Creating symbolic link %s with target directory %s' % (dest, target))
if os.path.exists(dest):
os.removeLists([], [dest])
os.symlink(target, dest) os.symlink(target, dest)
else: else:
target = destinations[0] target = destinations[0]
@ -583,10 +598,14 @@ class Setup():
if self.linking == HARD: if self.linking == HARD:
for dest in destinations[1:]: for dest in destinations[1:]:
print('Creating hard link %s with target file %s' % (dest, target)) print('Creating hard link %s with target file %s' % (dest, target))
if os.path.exists(dest):
os.unlink(dest)
os.link(target, dest) os.link(target, dest)
elif self.linking == SYMBOLIC: elif self.linking == SYMBOLIC:
for dest in destinations[1:]: for dest in destinations[1:]:
print('Creating symbolic link %s with target file %s' % (dest, target)) print('Creating symbolic link %s with target file %s' % (dest, target))
if os.path.exists(dest):
os.unlink(dest)
os.symlink(target, dest) os.symlink(target, dest)