mirror of
https://github.com/erkin/ponysay
synced 2024-11-23 11:53:14 +00:00
setup.py: Moved docstrings into the associated functions.
This commit is contained in:
parent
6a6fcbfe3f
commit
b9e9f00503
1 changed files with 82 additions and 63 deletions
145
setup.py
145
setup.py
|
@ -299,11 +299,12 @@ class Setup():
|
||||||
|
|
||||||
elif not method == 'view':
|
elif not method == 'view':
|
||||||
opts.help()
|
opts.help()
|
||||||
|
|
||||||
'''
|
|
||||||
Display configurations
|
|
||||||
'''
|
|
||||||
def viewconf(self, conf):
|
def viewconf(self, conf):
|
||||||
|
'''
|
||||||
|
Display configurations
|
||||||
|
'''
|
||||||
|
|
||||||
RED = '\033[31m%s\033[39m'
|
RED = '\033[31m%s\033[39m'
|
||||||
GREEN = '%s\033[32m%s\033[39m'
|
GREEN = '%s\033[32m%s\033[39m'
|
||||||
YELLOW = '\033[33m%s\033[39m'
|
YELLOW = '\033[33m%s\033[39m'
|
||||||
|
@ -351,11 +352,12 @@ class Setup():
|
||||||
else: print(RED % ('Installing \033[1mnot\033[21m only fully free parts of the package'))
|
else: print(RED % ('Installing \033[1mnot\033[21m only fully free parts of the package'))
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Compile ponysay
|
|
||||||
'''
|
|
||||||
def build(self, conf):
|
def build(self, conf):
|
||||||
|
'''
|
||||||
|
Compile ponysay
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mCompiling...\033[21m')
|
print('\033[1;34m::\033[39mCompiling...\033[21m')
|
||||||
|
|
||||||
def compressCommand(ext):
|
def compressCommand(ext):
|
||||||
|
@ -556,11 +558,12 @@ class Setup():
|
||||||
Popen(params, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
|
Popen(params, stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Install compiled ponysay
|
|
||||||
'''
|
|
||||||
def install(self, conf):
|
def install(self, conf):
|
||||||
|
'''
|
||||||
|
Install compiled ponysay
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mInstalling...\033[21m')
|
print('\033[1;34m::\033[39mInstalling...\033[21m')
|
||||||
|
|
||||||
dests = []
|
dests = []
|
||||||
|
@ -642,11 +645,12 @@ class Setup():
|
||||||
for file in miscfiles:
|
for file in miscfiles:
|
||||||
self.cp(False, file[0], [conf[file[0]]], Setup.validateFreedom if self.free else None)
|
self.cp(False, file[0], [conf[file[0]]], Setup.validateFreedom if self.free else None)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Uninstall ponysay
|
|
||||||
'''
|
|
||||||
def uninstall(self, conf):
|
def uninstall(self, conf):
|
||||||
|
'''
|
||||||
|
Uninstall ponysay
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mUninstalling...\033[21m')
|
print('\033[1;34m::\033[39mUninstalling...\033[21m')
|
||||||
|
|
||||||
(files, dirs, infos) = ([], [], [])
|
(files, dirs, infos) = ([], [], [])
|
||||||
|
@ -699,11 +703,12 @@ class Setup():
|
||||||
|
|
||||||
self.removeLists(files, dirs)
|
self.removeLists(files, dirs)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Uninstall file ponysay no longer uses
|
|
||||||
'''
|
|
||||||
def uninstallOld(self, conf):
|
def uninstallOld(self, conf):
|
||||||
|
'''
|
||||||
|
Uninstall file ponysay no longer uses
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mUninstalling old files...\033[21m')
|
print('\033[1;34m::\033[39mUninstalling old files...\033[21m')
|
||||||
|
|
||||||
instdir = conf['~prefix~'] + '/usr'
|
instdir = conf['~prefix~'] + '/usr'
|
||||||
|
@ -719,11 +724,12 @@ class Setup():
|
||||||
|
|
||||||
self.removeLists(files, dirs)
|
self.removeLists(files, dirs)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Remove compiled files
|
|
||||||
'''
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
'''
|
||||||
|
Remove compiled files
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mCleaning...\033[21m')
|
print('\033[1;34m::\033[39mCleaning...\033[21m')
|
||||||
|
|
||||||
files = ['ponysay.info', 'ponysay.info.gz', 'ponysay.info.xz', 'ponysay.pdf.gz', 'ponysay.pdf.xz', 'ponysay.install', 'ponysay.zip']
|
files = ['ponysay.info', 'ponysay.info.gz', 'ponysay.info.xz', 'ponysay.pdf.gz', 'ponysay.pdf.xz', 'ponysay.install', 'ponysay.zip']
|
||||||
|
@ -746,10 +752,11 @@ class Setup():
|
||||||
self.removeLists(files, dirs)
|
self.removeLists(files, dirs)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Remove compiled files ponysay is no longer compiling
|
|
||||||
'''
|
|
||||||
def cleanOld(self):
|
def cleanOld(self):
|
||||||
|
'''
|
||||||
|
Remove compiled files ponysay is no longer compiling
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1;34m::\033[39mCleaning old files...\033[21m')
|
print('\033[1;34m::\033[39mCleaning old files...\033[21m')
|
||||||
|
|
||||||
files = ['truncater', 'ponysaytruncater', 'ponysay.py.install', 'ponysay.install~', 'ponysay.zip']
|
files = ['truncater', 'ponysaytruncater', 'ponysay.py.install', 'ponysay.install~', 'ponysay.zip']
|
||||||
|
@ -763,11 +770,12 @@ class Setup():
|
||||||
|
|
||||||
self.removeLists(files, dirs)
|
self.removeLists(files, dirs)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
'''
|
|
||||||
Removes listed files and directories
|
|
||||||
'''
|
|
||||||
def removeLists(self, files, dirs):
|
def removeLists(self, files, dirs):
|
||||||
|
'''
|
||||||
|
Removes listed files and directories
|
||||||
|
'''
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
if os.path.isfile(file) or os.path.islink(file):
|
if os.path.isfile(file) or os.path.islink(file):
|
||||||
print('Unlinking file %s' % (file))
|
print('Unlinking file %s' % (file))
|
||||||
|
@ -792,12 +800,13 @@ class Setup():
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
else:
|
else:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
'''
|
|
||||||
Check whether a file is fully free
|
|
||||||
'''
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validateFreedom(filename):
|
def validateFreedom(filename):
|
||||||
|
'''
|
||||||
|
Check whether a file is fully free
|
||||||
|
'''
|
||||||
|
|
||||||
if not os.path.isdir(filename):
|
if not os.path.isdir(filename):
|
||||||
if filename.endswith('.pony') and (filename != '.pony') and not filename.endswith('/.pony'):
|
if filename.endswith('.pony') and (filename != '.pony') and not filename.endswith('/.pony'):
|
||||||
with open(filename, 'rb') as file:
|
with open(filename, 'rb') as file:
|
||||||
|
@ -812,11 +821,12 @@ class Setup():
|
||||||
return line[1].lower() == 'yes'
|
return line[1].lower() == 'yes'
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
'''
|
|
||||||
Copys a files or directory to multiple destinations
|
|
||||||
'''
|
|
||||||
def cp(self, recursive, source, destinations, validatehook = None):
|
def cp(self, recursive, source, destinations, validatehook = None):
|
||||||
|
'''
|
||||||
|
Copys a files or directory to multiple destinations
|
||||||
|
'''
|
||||||
|
|
||||||
if validatehook is not None:
|
if validatehook is not None:
|
||||||
if not validatehook(source):
|
if not validatehook(source):
|
||||||
print('Ignoring installation of file %s (did not pass validation process made by setup settings)' % source)
|
print('Ignoring installation of file %s (did not pass validation process made by setup settings)' % source)
|
||||||
|
@ -890,11 +900,12 @@ class Setup():
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
os.unlink(dest)
|
os.unlink(dest)
|
||||||
self.symlink(target, dest)
|
self.symlink(target, dest)
|
||||||
|
|
||||||
'''
|
|
||||||
Create a symlink with a relative path
|
|
||||||
'''
|
|
||||||
def symlink(self, target, dest):
|
def symlink(self, target, dest):
|
||||||
|
'''
|
||||||
|
Create a symlink with a relative path
|
||||||
|
'''
|
||||||
|
|
||||||
if target.startswith('./') or target.startswith('../'):
|
if target.startswith('./') or target.startswith('../'):
|
||||||
os.symlink(target, dest)
|
os.symlink(target, dest)
|
||||||
elif '/' not in target:
|
elif '/' not in target:
|
||||||
|
@ -914,10 +925,11 @@ class Setup():
|
||||||
|
|
||||||
os.symlink('/'.join(targets), dest)
|
os.symlink('/'.join(targets), dest)
|
||||||
|
|
||||||
'''
|
|
||||||
Parses configurations
|
|
||||||
'''
|
|
||||||
def configure(self, opts):
|
def configure(self, opts):
|
||||||
|
'''
|
||||||
|
Parses configurations
|
||||||
|
'''
|
||||||
|
|
||||||
(defaults, conf) = ({}, {})
|
(defaults, conf) = ({}, {})
|
||||||
|
|
||||||
for command in commands:
|
for command in commands:
|
||||||
|
@ -1070,15 +1082,18 @@ class Setup():
|
||||||
|
|
||||||
ARGUMENTLESS = 0
|
ARGUMENTLESS = 0
|
||||||
ARGUMENTED = 1
|
ARGUMENTED = 1
|
||||||
'''
|
|
||||||
Simple argument parser, a strip down of the one in ponysay and slitly modified
|
|
||||||
'''
|
|
||||||
class ArgParser():
|
class ArgParser():
|
||||||
'''
|
'''
|
||||||
Constructor.
|
Simple argument parser, a strip down of the one in ponysay and slitly modified
|
||||||
The short description is printed on same line as the program name
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, program, description, usage, longdescription = None):
|
def __init__(self, program, description, usage, longdescription = None):
|
||||||
|
'''
|
||||||
|
Constructor.
|
||||||
|
The short description is printed on same line as the program name
|
||||||
|
'''
|
||||||
|
|
||||||
self.__program = program
|
self.__program = program
|
||||||
self.__description = description
|
self.__description = description
|
||||||
self.__usage = usage
|
self.__usage = usage
|
||||||
|
@ -1086,27 +1101,30 @@ class ArgParser():
|
||||||
self.__arguments = []
|
self.__arguments = []
|
||||||
(self.opts, self.optmap) = ({}, {})
|
(self.opts, self.optmap) = ({}, {})
|
||||||
|
|
||||||
'''
|
|
||||||
Add option that takes no arguments
|
|
||||||
'''
|
|
||||||
def add_argumentless(self, alternatives, help = None):
|
def add_argumentless(self, alternatives, help = None):
|
||||||
|
'''
|
||||||
|
Add option that takes no arguments
|
||||||
|
'''
|
||||||
|
|
||||||
ARGUMENTLESS
|
ARGUMENTLESS
|
||||||
self.__arguments.append((ARGUMENTLESS, alternatives, None, help))
|
self.__arguments.append((ARGUMENTLESS, alternatives, None, help))
|
||||||
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
||||||
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTLESS)
|
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTLESS)
|
||||||
|
|
||||||
'''
|
|
||||||
Add option that takes one argument
|
|
||||||
'''
|
|
||||||
def add_argumented(self, alternatives, arg, help = None):
|
def add_argumented(self, alternatives, arg, help = None):
|
||||||
|
'''
|
||||||
|
Add option that takes one argument
|
||||||
|
'''
|
||||||
|
|
||||||
self.__arguments.append((ARGUMENTED, alternatives, arg, help))
|
self.__arguments.append((ARGUMENTED, alternatives, arg, help))
|
||||||
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
(stdalt, self.opts[stdalt]) = (alternatives[0], None)
|
||||||
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTED)
|
for alt in alternatives: self.optmap[alt] = (stdalt, ARGUMENTED)
|
||||||
|
|
||||||
'''
|
|
||||||
Parse arguments
|
|
||||||
'''
|
|
||||||
def parse(self, argv = sys.argv):
|
def parse(self, argv = sys.argv):
|
||||||
|
'''
|
||||||
|
Parse arguments
|
||||||
|
'''
|
||||||
|
|
||||||
self.argcount = len(argv) - 1
|
self.argcount = len(argv) - 1
|
||||||
self.files = []
|
self.files = []
|
||||||
(argqueue, optqueue, get) = ([], [], False)
|
(argqueue, optqueue, get) = ([], [], False)
|
||||||
|
@ -1152,10 +1170,11 @@ class ArgParser():
|
||||||
sys.stderr.write('%s: fatal: duplicate option %s\n' % (self.__program, arg))
|
sys.stderr.write('%s: fatal: duplicate option %s\n' % (self.__program, arg))
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
'''
|
|
||||||
Prints a colourful help message
|
|
||||||
'''
|
|
||||||
def help(self):
|
def help(self):
|
||||||
|
'''
|
||||||
|
Prints a colourful help message
|
||||||
|
'''
|
||||||
|
|
||||||
print('\033[1m%s\033[21m - %s\n' % (self.__program, self.__description))
|
print('\033[1m%s\033[21m - %s\n' % (self.__program, self.__description))
|
||||||
if self.__longdescription is not None:
|
if self.__longdescription is not None:
|
||||||
print(self.__longdescription)
|
print(self.__longdescription)
|
||||||
|
|
Loading…
Reference in a new issue