Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
[#4] general: misc bugs (#7)
Browse files Browse the repository at this point in the history
* ctrl/issues: import sys module

* main: log WARN and higher to stderr + extract logger setup

* ctrl/issues: fix bug when no mapping file is supplied
  • Loading branch information
Skaty authored Apr 5, 2018
1 parent f84fb35 commit 0a45cf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions controllers/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .common import BaseController
import parsers

import logging, re, time
import logging, re, time, sys

class IssueController(BaseController):
def __init__(self, ghc):
Expand Down Expand Up @@ -55,7 +55,7 @@ def blast_command(self, args):
def copy_command(self, args):
logging.debug('Copying from %s to %s', args.fromrepo, args.torepo)

if parsers.common.are_files_readable(args.mapping):
if args.mapping is None or parsers.common.are_files_readable(args.mapping):
self.copy_issues(args.mapping, args.fromrepo, args.torepo, args.start_from)
else:
sys.exit(1)
Expand All @@ -65,7 +65,7 @@ def copy_issues(self, mapping_file, fromrepo, torepo, offset):
Copies issues from one repository to another
'''
first_repo_issues = self.ghc.get_issues_from_repository(fromrepo)
mapping_dict = parsers.csvparser.get_rows_as_dict(mapping_file)
mapping_dict = parsers.csvparser.get_rows_as_dict(mapping_file) if mapping_file is not None else {}
REF_TEMPLATE = '\n\n<sub>[original: {}#{}]</sub>'

if not offset:
Expand Down
13 changes: 11 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

import argparse, logging, sys

logging.basicConfig(filename='log.log',level=logging.DEBUG)

cfg = AppConfig()
ghc = GitHubConnector(cfg.get_api_key(), cfg.get_repo(), cfg.get_organisation())
issue_ctrl = IssueController(ghc)
org_ctrl = OrganisationController(ghc)

def setup_logger():
"""Sets up the logger"""
logging.basicConfig(filename='log.log',level=logging.DEBUG)

console = logging.StreamHandler()
console.setLevel(logging.WARNING)
formatter = logging.Formatter('[%(levelname)s] %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)

def setup_argparse():
"""Sets up argparse"""
parser = argparse.ArgumentParser(description='useful command line tools for GitHub')
Expand All @@ -23,6 +31,7 @@ def setup_argparse():
return parser

if __name__ == '__main__':
setup_logger()
logging.info('hubatch - GitHub CLI tools: Started!')
parser = setup_argparse()
args = parser.parse_args()
Expand Down

0 comments on commit 0a45cf2

Please sign in to comment.