|
1 | | -def main(): |
2 | | - """Main script for pythonBootCamp project |
| 1 | +# LIBRARIES |
| 2 | +from sys import argv |
| 3 | + |
| 4 | +from exerciseeight.filemanage import FileManager |
| 5 | + |
| 6 | +# CONSTANT |
| 7 | +PATH = 'src/files/path.txt' |
| 8 | + |
| 9 | + |
| 10 | +# FUNCTIONS |
| 11 | +def argsTransformation(args: list[str], argc: int) -> str: |
| 12 | + """Function to process main arguments in a sigle string |
| 13 | + :param args: string list to be processed |
| 14 | + :type args: list[str] |
| 15 | + :param argc: size of args |
| 16 | + :type argc: int |
| 17 | + :return: string list in a unique string |
| 18 | + :rtype: str |
| 19 | + """ |
| 20 | + text = '' |
| 21 | + for arg in args[1:argc]: |
| 22 | + if arg == args[argc - 1]: |
| 23 | + text += arg |
| 24 | + else: |
| 25 | + text += arg + ' ' |
| 26 | + text += '\n' |
| 27 | + return text |
| 28 | + |
| 29 | + |
| 30 | +def readPaths() -> tuple[str, str]: |
| 31 | + """Function to read a file with path.txt data |
| 32 | + :return: return path.txt and filename |
| 33 | + :rtype: tuple[str, str] |
| 34 | + """ |
| 35 | + f = open(PATH, 'r') |
| 36 | + paths = f.readlines() |
| 37 | + f.close() |
| 38 | + split = [] |
| 39 | + for path in paths: |
| 40 | + split.append(path.split('=')) |
| 41 | + path = '' |
| 42 | + filename = '' |
| 43 | + for linea in split: |
| 44 | + if linea[0] == 'PATH': |
| 45 | + path = linea[1].replace('\n', '') |
| 46 | + if linea[0] == 'FILENAME': |
| 47 | + filename = linea[1].replace('\n', '') |
| 48 | + return path, filename |
| 49 | + |
| 50 | + |
| 51 | +# MAIN FUNCTION |
| 52 | +def main(args, argc): |
| 53 | + """Main script for exercise eight A |
3 | 54 | :return: None |
4 | 55 | :rtype: NoneType |
5 | 56 | """ |
6 | | - pass |
| 57 | + # Convert arguments in one string |
| 58 | + text = argsTransformation(args, argc) |
| 59 | + # Take path.txt and filename from files/path.txt |
| 60 | + path, filename = readPaths() |
| 61 | + # Create file manager object |
| 62 | + f = FileManager(path, filename) |
| 63 | + # Create text file |
| 64 | + f.createTextFile() |
| 65 | + # Write arguments in text file |
| 66 | + f.writeTextFile(text) |
7 | 67 |
|
8 | 68 |
|
9 | 69 | if __name__ == '__main__': |
10 | | - main() |
| 70 | + main(argv, len(argv)) |
0 commit comments