コード例 #1
0
def main():
  fig = plt.figure()
  ax = plt.subplot(111)

  if len(sys.argv) == 1:
    fn = identity
  else:
    try:
      fn = globals()[sys.argv[1]]
    except KeyError:
      helper.warn('Unknown function: "{}"'.format(sys.argv[1]))
      return
  fn(fig, ax)

  plt.show()
コード例 #2
0
def run():
    accentuate("Starting the Public Computer Cleaner!")
    log(f"Created by {AUTHOR}. Version {VERSION}. Repo: {REPO}.\n")
    progVars = getVariables()
    if not progVars['on-switch']:
        warn("Stopping program. Global ON switch is set to 'OFF'.")
        return
    if progVars['monthly-reporter'] == progVars['computer-name']:
        checkIfDate(progVars['sendgrid-api-key'], progVars['monthly-reporter-debug'], progVars['computer-name'], progVars['from-email'], progVars['to-email'], progVars['email-subject'])
    else:
        log("Did not check if monthly report needed to be sent because this computer is not the monthly reporter.")
    runSecPref = progVars['alert-before-run']
    if runSecPref:
        log("Alerting before run, in accordance with variable setting.")
        showToast("Computer cleaner begins in 15 seconds.", "This removes all local information. To avoid this, please move the mouse.", duration=10, threaded=True)
        alertSound(1)
        time.sleep(9)
        showToast("Computer cleaner begins in 5 seconds.", "This removes all local information. To avoid this, please move the mouse.", duration=5, threaded=True)
        alertSound(5)
    log("Starting timer.")
    startCleanTime = time.perf_counter()
    log("Calling Cleaner algorithm...")
    cleanerResults = runCleaner()
    success("Completed Cleaner algorithm.")
    log("Calling Chrome algorithm...")
    chromeResults = runChrome()
    log("Calling Edge algorithm...")
    edgeResults = runEdge()
    log("Calling Windows algorithm...")
    windowsResults = runWindows(progVars['keep-name-regex'], progVars['keep-vendor-regex'])
    log("Completed all algorithms.")
    log("Compiling stats of this run.")
    res = {}
    res.update(cleanerResults)
    res.update(chromeResults)
    res.update(edgeResults)
    res.update(windowsResults)
    res.update({'times-ran': 1})
    log("Attempting to send results of run.")
    sendResults(progVars['computer-name'], res)
    sendLogs(progVars['computer-name'], res)
    endCleanTime = time.perf_counter()
    log(f'Completed in {endCleanTime - startCleanTime:0.4f} s')
コード例 #3
0
def uninstallUselessPrograms(nameString, vendorString):
    w = wmi.WMI()
    deletedNames = []
    for p in w.Win32_Product():
        nameMatches = re.findall(nameString, p.name, re.I)
        vendorMathces = re.findall(vendorString, p.vendor, re.I)
        if len(nameMatches) > 0:
            log("Keeping " + p.name + " because it matched a name keep RegEx.")
        if len(vendorMathces) > 0:
            log("Keeping " + p.name +
                " because it matched a vendor keep RegEx.")
        else:
            warn("Deleting " + p.name + ".")
            deleteProgram(p.name)
            log("Attempted to delete " + p.name + ".")
            deletedNames.append(p.name)
    allNames = []
    for p in w.Win32_Product():
        allNames.append(p.name)
    for d in deletedNames:
        if d not in allNames:
            log("Confirmed successful deletion of " + d + ".")
    return len(deletedNames)
コード例 #4
0
def getVariables():
    log("Attempting to get values for needed variables.")
    vals = sh.worksheet("Global Variables").get('B5:J14')
    log("Obtained values from Google Sheet.")
    # SendGrid API Key
    sendGridAPIKey = getVariable('SENDGRID_API_KEY')
    if sendGridAPIKey == False:
        try:
            sendGridAPIKey = vals[0][2]
        except:
            raise ValueError("SENDGRID_API_KEY has no value.")
    # On/off switch
    onOff = getVariable('GLOBAL_ON_SWITCH')
    if onOff == False:
        try:
            onOff = vals[1][2]
            if len(onOff) < 1:
                warn("GLOBAL_ON_SWITCH not formally declared. Assuming ON.")
                onOff = True
            else:
                onOff = (onOff == "ON")
        except:
            warn("GLOBAL_ON_SWITCH not formally declared. Assuming ON.")
            onOff = True
    else:
        onOff = (onOff == "ON")
    # Alert Before Run option
    alertBeforeRun = getVariable('ALERT_BEFORE_RUN')
    if alertBeforeRun == False:
        try:
            alertBeforeRun = vals[2][2]
            if len(alertBeforeRun) < 1:
                warn("ALERT_BEFORE_RUN not formally declared. Assuming ON.")
                alertBeforeRun = True
            else:
                alertBeforeRun = (alertBeforeRun == "ON")
        except:
            warn("ALERT_BEFORE_RUN not formally declared. Assuming ON.")
            alertBeforeRun = True
    else:
        alertBeforeRun = (alertBeforeRun == "ON")
    # Keep Name RegEx
    keepNameRegex = getVariable('KEEP_NAME_REGEX')
    if keepNameRegex == False:
        try:
            keepNameRegex = vals[3][2]
        except:
            raise ValueError("KEEP_NAME_REGEX has no value.")
    # Keep Vendor RegEx
    keepVendorRegex = getVariable('KEEP_VENDOR_REGEX')
    if keepVendorRegex == False:
        try:
            keepVendorRegex = vals[4][2]
        except:
            raise ValueError("KEEP_VENDOR_REGEX has no value.")
    # Computer Name
    compName = getVariable('COMPUTER_NAME')
    if compName == False:
        raise ValueError(
            "COMPUTER_NAME is not defined in settings.txt. Without this, the program can not identify which page to send logs to."
        )
    # Monthly Reporter
    monthlyReporter = getVariable('MONTHLY_REPORTER')
    if monthlyReporter == False:
        try:
            monthlyReporter = vals[5][2]
        except:
            raise ValueError("MONTHLY_REPORTER has no value.")
    # Monthly Reporter Debug
    monthlyReporterDebug = getVariable('MONTHLY_REPORTER_DEBUG')
    if monthlyReporterDebug == False:
        try:
            monthlyReporterDebug = vals[6][2]
            if len(monthlyReporterDebug) < 1:
                warn(
                    "MONTHLY_REPORTER_DEBUG not formally declared. Assuming OFF."
                )
                monthlyReporterDebug = False
            else:
                monthlyReporterDebug = (monthlyReporterDebug == "ON")
        except:
            warn("MONTHLY_REPORTER_DEBUG not formally declared. Assuming OFF.")
            monthlyReporterDebug = False
    else:
        monthlyReporterDebug = (monthlyReporterDebug == "ON")
    # From Email
    fromEmail = getVariable('FROM_EMAIL')
    if fromEmail == False:
        try:
            fromEmail = vals[7][2]
        except:
            raise ValueError("FROM_EMAIL has no value.")
    # To Email
    toEmail = getVariable('TO_EMAIL')
    if toEmail == False:
        try:
            toEmail = vals[8][2]
        except:
            raise ValueError("TO_EMAIL has no value.")
    # Subject
    emailSubject = getVariable('EMAIL_SUBJECT')
    if emailSubject == False:
        try:
            emailSubject = vals[9][2]
            if len(emailSubject) < 1:
                warn(
                    "EMAIL_SUBJECT not formally declared. Assuming ' [AUTO] Public Computer Cleaner Monthly Report'."
                )
                emailSubject = ' [AUTO] Public Computer Cleaner Monthly Report'
        except:
            warn("EMAIL_SUBJECT not formally declared. Assuming OFF.")
            emailSubject = ' [AUTO] Public Computer Cleaner Monthly Report'
    log("Successfully attemped to find all values for program.")
    return {
        'sendgrid-api-key': sendGridAPIKey,
        'on-switch': onOff,
        'alert-before-run': alertBeforeRun,
        'keep-name-regex': keepNameRegex,
        'keep-vendor-regex': keepVendorRegex,
        'computer-name': compName,
        'monthly-reporter': monthlyReporter,
        'monthly-reporter-debug': monthlyReporterDebug,
        'from-email': fromEmail,
        'to-email': toEmail,
        'email-subject': emailSubject,
    }