Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- whitelisted_apps = [] # app
- blacklisted_apps = [] # app
- restrict_list = {} # app:[user1, ...]
- new_apps = {} # app:[user1, ...]
- # read the restrict list to an app:[users] array dict
- try:
- restrict_list_reader = csv.reader(open('restricted_apps.csv'), delimiter=";")
- for row in restrict_list_reader:
- app = row[0]
- user = row[1]
- restrict_list.setdefault(app, [])
- restrict_list[app].append(user)
- except:
- pass
- # read the blacklisted app list to an array
- ## BUGFIX: must be CSV to support BS formatting
- try:
- blacklist_reader = csv.reader(open('blacklisted_apps.csv'), delimiter=";")
- for row in blacklist_reader:
- blacklisted_apps.append(row[0])
- except:
- pass
- # read the whitelisted app list to an array
- ## BUGFIX: must be CSV to support BS formatting
- try:
- whitelist_reader = csv.reader(open('whitelisted_apps.csv'), delimiter=";")
- for row in whitelist_reader:
- whitelisted_apps.append(row[0])
- except:
- pass
- # read the current app list to an app:[users] array dict, print if blacklisted or restricted
- print("\nSpecial events:\n")
- newlist_reader = csv.reader(open('all_apps_full.csv'), delimiter=";")
- for row in newlist_reader:
- app = row[0]
- user = row[1]
- if not app in whitelisted_apps: # not already whitelisted
- if not app in blacklisted_apps: # not blacklisted
- if not app in restrict_list: # not restricted to certain users (selective whitelist)
- new_apps.setdefault(app, [])
- new_apps[app].append(user)
- elif not user in restrict_list[app]:
- print("Restricted: " + app + " on " + user)
- else:
- print("Blacklisted: " + app + " on " + user)
- # print all new apps
- print("\nNew apps list:\n")
- for entry in new_apps:
- print(entry + "\ton " + ", ".join(new_apps[entry][0:]))
- # write all apps to a temp whitelist csv
- ## BUGFIX: must be CSV to support BS formatting
- try:
- with open('tmp_whitelisted_apps.csv', 'w') as temp_whitelist:
- for entry in new_apps:
- temp_whitelist.write("%s;\n" % entry)
- except:
- print("\nwarning: failed to create a temp whitelist\n")
Add Comment
Please, Sign In to add comment