def main(): args = len(sys.argv) if args < 2: filename = os.path.join(PROJECT_ROOT, './data/printer_account.csv') else: filename = os.path.abspath(sys.argv[1]) dir_, _ = os.path.split(filename) if not os.path.exists(dir_): os.makedirs(dir_) month = None if args > 2: try: month = int(sys.argv[2]) except ValueError: raise ValueError("2nd argument should be an integer which represents month") print("Generating accounting information. Please wait...") _, compact_file, verbose_file = account(custom_acc_file=filename, verbose=True, month=month) print("Accounting information is generated in directory %s" % os.path.dirname(filename)) print("Generated files are %s and %s" % (compact_file, verbose_file))
printer_name = config.get('printer', 'name') try: username, login_status = login() except (OAuthError, ValueError, socket_error) as err: msg = 'Unable to Authenticate. \nError: %s\n' % err.message sys.stderr.write(RED + msg + NATIVE) sys.stderr.flush() sys.exit() if login_status: sys.stdout.write(GREEN + 'Authentication Successful\n' + NATIVE) sys.stdout.flush() choice = selection() while choice != 3: if choice == 1: job_id = cups_print(username, printer_name) if choice == 2: total_pages, _, _ = account(username) eg.msgbox( 'Total number of pages printed in current month = %s' % total_pages, 'Total Printed Pages') choice = selection() else: print('Login failed. Please try again later') stop_server() sys.exit()
config = ConfigParser.ConfigParser() config.read(os.path.join(PROJECT_ROOT, "config/printer.cfg")) printer_name = config.get('printer', 'name') try: username, login_status = login() except (OAuthError, ValueError, socket_error) as err: msg = 'Unable to Authenticate. \nError: %s\n' % err.message sys.stderr.write(RED + msg + NATIVE) sys.stderr.flush() sys.exit() if login_status: sys.stdout.write(GREEN + 'Authentication Successful\n' + NATIVE) sys.stdout.flush() choice = selection() while choice != 3: if choice == 1: job_id = cups_print(username, printer_name) if choice == 2: total_pages, _, _ = account(username) eg.msgbox('Total number of pages printed in current month = %s' % total_pages, 'Total Printed Pages') choice = selection() else: print('Login failed. Please try again later') sys.exit()