Commit c7403ada authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Change shebang to use python3. Minor fixes.

parent 7e71429a
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import boxsdk
import kadmin
......@@ -389,7 +389,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
sa = SharedAccount(args, config)
sa = SharedAccount(vars(args), config)
sa.set_up_mcommunity_group()
sa.set_kerberos_password()
if sa.service in ['box', 'both']:
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import boxsdk
import kadmin
......@@ -16,9 +16,8 @@ from subprocess import STDOUT
class SharedAccount():
def __init__(self, account, password, config):
self.account = account
self.password = password
def __init__(self, args, config):
self.__dict__.update(args)
self.config = config
self.box_exists = False
self.google_exists = False
......@@ -87,7 +86,7 @@ class SharedAccount():
self.logger.error(e, extra={'entity': self.account})
exit(2)
except kadmin.KAdminError as e:
self.logger.error(e, extra={'entity': self.account})
self.logger.error(e['message'], extra={'entity': self.account})
exit(2)
def set_google_password(self):
......@@ -243,11 +242,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
sa = SharedAccount(
args.account,
args.password,
config
)
sa = SharedAccount(vars(args), config)
sa.check_mcommunity()
sa.check_box()
sa.check_google()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import re
import yaml
......@@ -228,7 +228,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
group = DiscussionGroup(args, config)
group = DiscussionGroup(vars(args), config)
group.create_group()
group.add_group_owners()
group.add_group_members()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import csv
import logging
......@@ -432,7 +432,7 @@ Used with login reporting to account for inherant delay.''',
logger.addHandler(ch)
if args.daily:
archiver = Archiver(args, config)
archiver = Archiver(vars(args), config)
userP = Process(target=archiver.log_users)
groupP = Process(target=archiver.log_groups)
resourceP = Process(target=archiver.log_resources)
......@@ -449,7 +449,7 @@ Used with login reporting to account for inherant delay.''',
oauthP.join()
if args.hourly:
archiver = Archiver(args, config)
archiver = Archiver(vars(args), config)
logP = Process(target=archiver.log_logins)
logP.start()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import yaml
import logging
......@@ -128,7 +128,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
fba = Account(args, config)
fba = Account(vars(args), config)
fba.create_labels_and_filters()
......
#!/usr/bin/env python
# Copyright 2017 Rob Carleski, The University of Michigan
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#!/usr/bin/env python3
import argparse
import json
import re
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import csv
import logging
......@@ -222,7 +222,7 @@ class Sifter:
def upload_logfiles(self):
try:
if hasattr(self, 'destination_account'):
if self.destination_account:
upload_user = self.destination_account
else:
upload_user = str(os.getlogin())
......@@ -255,11 +255,14 @@ class Sifter:
'drivefilename',
gFolderName,
'mimetype',
'vnd.google-apps.folder'
'gdirectory'
], stderr=devnull
)
except CalledProcessError as e:
self.logger.error(e.output, extra={'entity': self.account})
self.logger.error(
'Unable to create report directory',
extra={'entity': self.account}
)
for log_file in available_files:
try:
......@@ -277,7 +280,10 @@ class Sifter:
], stderr=devnull
)
except CalledProcessError as e:
self.logger.error(e.output, extra={'entity': self.account})
self.logger.error(
'Error uploading {}'.format(log_file),
extra={'entity': self.account}
)
rmtree(self.log_path)
......@@ -323,7 +329,7 @@ def main():
'--destination_account',
'-d',
help='An optional account to upload reports to.',
required=False
default=False
)
parser.add_argument(
'--skip_upload',
......@@ -363,7 +369,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
sifter = Sifter(args, config)
sifter = Sifter(vars(args), config)
sifter.sift(args.root_folder)
sifter.find_unorganized()
sifter.find_shared()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import logging
import logging.handlers
......@@ -128,7 +128,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
sifter = Sifter(args, config)
sifter = Sifter(vars(args), config)
sifter.sift()
sifter.print_sifted_labels()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import logging
import logging.handlers
......@@ -176,7 +176,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
mover = Mover(args, config)
mover = Mover(vars(args), config)
mover.transfer_files()
......
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import logging
import logging.handlers
......@@ -315,7 +315,7 @@ def main():
ch.setFormatter(formatter)
logger.addHandler(ch)
mover = Mover(args, config)
mover = Mover(vars(args), config)
mover.transfer_mail()
mover.cleanup()
......
......@@ -9,13 +9,13 @@ import yaml
from unittest import mock
data_dir = os.path.join(os.path.dirname(__file__) + '/data/')
script_dir = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
script = script_dir + '/collab_reset_shared.py'
config = data_dir + 'test_cak_config.yml'
sa = collab_reset_shared.SharedAccount(
'testsharedaccount',
'pass12word',
{
'account': 'testsharedaccount',
'password': 'pass12word'
},
yaml.load(open(config), Loader=yaml.BaseLoader)
)
......
......@@ -90,6 +90,7 @@ def test_sift_skip_upload(mock_login):
mock_login.return_value('testuser')
args = {
'account': 'testuser',
'destination_account': False,
'root_folder': 'root'
}
sifter = google_sift_drive.Sifter(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment