|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import time |
| 6 | +import subprocess |
| 7 | + |
| 8 | +import BBSutils |
| 9 | +import BBSvars |
| 10 | +import BBSbase |
| 11 | + |
| 12 | +def make_meta(): |
| 13 | + ## Prepare Rexpr (must be a single string with no spaces). |
| 14 | + Rscript_path = os.path.join(BBSvars.BBS_home, |
| 15 | + 'utils', |
| 16 | + 'generateMetaDbs.R') |
| 17 | + Rfun = 'generateMetaDbs' |
| 18 | + OUTGOING_dir = 'OUTGOING' |
| 19 | + db_filepath = 'PROPAGATION_STATUS_DB.txt' |
| 20 | + Rfuncall = f"{Rfun}('{OUTGOING_dir}','{db_filepath}')" |
| 21 | + Rexpr = f"source('{Rscript_path}');{Rfuncall}" |
| 22 | + |
| 23 | + ## Turn Rexpr into a system command. |
| 24 | + cmd = BBSbase.Rexpr2syscmd(Rexpr) |
| 25 | + |
| 26 | + try: |
| 27 | + ## Nasty things (that I don't really understand) can happen with |
| 28 | + ## subprocess.run() if this code is runned by the Task Scheduler |
| 29 | + ## on Windows (the child process tends to almost always return an |
| 30 | + ## error). Apparently using 'stderr=subprocess.STDOUT' fixes this pb. |
| 31 | + subprocess.run(cmd, stdout=None, stderr=subprocess.STDOUT, shell=True, |
| 32 | + check=True) |
| 33 | + except subprocess.CalledProcessError as e: |
| 34 | + print(f'BBS> [generateMetaDbs] Failed at {time.asctime()} . . .') |
| 35 | + print(f'BBS> [generateMetaDbs] Error: {e} . . .') |
| 36 | + return |
| 37 | + |
| 38 | + |
| 39 | +############################################################################## |
| 40 | +### MAIN SECTION |
| 41 | +############################################################################## |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + if not os.path.isfile('PROPAGATION_STATUS_DB.txt'): |
| 45 | + msg = ( |
| 46 | + f'Make sure to be in {BBSvars.Central_rdir.path} and run ' |
| 47 | + f'BBS-make-PROPAGATION_STATUS_DB.py before BBS-make-meta.py.' |
| 48 | + ) |
| 49 | + sys.exit('=> EXIT.') |
| 50 | + print('BBS> ==============================================================') |
| 51 | + print(f'BBS> [generateMetaDbs] STARTING on {time.asctime()} ...') |
| 52 | + sys.stdout.flush() |
| 53 | + generate_meta_dbs() |
| 54 | + print(f'BBS> [generateMetaDbs] DONE on {time.asctime()} ...') |
| 55 | + |
0 commit comments