| # Name: BitCode/BitFlag Python Example | |
| # Author: Bryan McIntosh | |
| ###################################################################### | |
| # Set bitCode/Flag to run various/multiple sections of code. | |
| # Add the numbers together for each section to run. | |
| # 1: Call section 0 - example: Clean temp directory | |
| # 2: Call section 1 - example: Run FTP Download | |
| # 4: Call section 2 - example: Analyze FTP files and clean | |
| # 8: Call section 3 - example: Say hi | |
| ###################################################################### | |
| ##fn_bits: Calculate binary (base2) numbers from integer (base10) | |
| def fn_bits(n): | |
| while n: | |
| b = n & (~n+1) | |
| yield b | |
| n ^= b | |
| #End function fn_bits | |
| bitRunCode = 9 #This is default, Runs 1 and 8 (1+8=9). Providing runtime argument[1] will override | |
| if len(sys.argv) == 2: | |
| try: | |
| bitRunCode = int(sys.argv[1]) | |
| except: | |
| print 'Invalid runtime argument, exiting program without running' | |
| sys.exit() | |
| for b in fn_bits(bitRunCode): | |
| if b == 1: | |
| print 'Call section 0: Clean directory' | |
| elif b == 2: | |
| print '\n Call section 1: FTP' | |
| elif b == 4: | |
| print '\n Call section 2: Analyze' | |
| elif b == 8: | |
| print '\n Call section 3: Hi! | |
| else: | |
| print 'bitRunCode not in range - but you can always add more.' | |
| #FIN |