copy_cgi_files.html


001| '''Copy PY files from WWW Bin (and add PY extention).'''
002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from shutil import copy2 as CopyFile
006| from files import fileobj, linefile
007| ####################################################################################################
008| BasePath = r'C:\CJS\prj\Python\app'
009| CopyPath = r'C:\CJS\prj\Python\site\cgi'
010| SitePath = r'C:\CJS\www\_bin'
011| FilePath = r'C:\CJS\www\_dat\config'
012| FileList = 'cgi-py-files.list'
013| 
014| 
015| ##================================================================================================##
016| def copy_py_files (filelist, srcpath=SitePath, dstpath=CopyPath):
017|     '''Copy (and rename) a list of files to the backup bin.'''
018|     for name in filelist:
019|         # Generate source and destination filenames...
020|         src = path.join(srcpath, name)
021|         if name.endswith('.py'):
022|             dst = path.join(dstpath, name)
023|         else:
024|             dst = path.join(dstpath, f'{name}.py')
025|         print(src)
026|         print(dst)
027| 
028|         # If it's a valid file...
029|         fsrc = fileobj(src)
030|         fdst = fileobj(dst)
031|         if fsrc.fflag:
032|             # Copy that file...
033|             rc = CopyFile(src, dst)
034|             print(f'CopyFile returned {rc}')
035|         else:
036|             # Oops...
037|             print('NO FILE FOUND!')
038|         print()
039| 
040| 
041| ##================================================================================================##
042| def main (*args):
043|     fn = path.join(FilePath, FileList)
044|     fo = linefile(fn)
045|     fo.load()
046| 
047|     copy_py_files(fo.data)
048| 
049|     return fo.data
050| 
051| ####################################################################################################
052| if __name__ == "__main__":
053|     print(f'autorun: {argv[0]}')
054|     rv = main(*argv[1:])
055|     print()
056| ####################################################################################################
057| '''eof'''
058|