# Path: git_trac/logger.py
# def make_logger(name, doctest_mode=False):
# def enable_doctest_mode():
# 
# Path: git_trac/ticket_or_branch.py
# class TicketOrBranch(object):
# 
#     def __init__(self, name):
#         self._name = name
#         self._validate()
# 
#     def __int__(self):
#         try:
#             return int(self._name)        
#         except ValueError:
#             pass
# 
#     def __str__(self):
#         return self._name
# 
#     def is_number(self):
#         try:
#             int(self._name)
#             return True
#         except ValueError:
#             return False
# 
#     def is_branch(self):
#         for prefix in ['u/', 'public/']:
#             if self._name.startswith(prefix):
#                 return True
#         if self._name in ['master', 'develop']:
#             return True
#         return False
# 
#     def _validate(self):
#         if self.is_number() or self.is_branch():
#             return
#         raise ValueError('Not a valid ticket number or remote branch name')


import sys
import os
import warnings
import argparse
    import subprocess
        import importlib
        import logging
from .logger import logger
from .ticket_or_branch import TicketOrBranch
    from IPython.terminal.ipapp import TerminalIPythonApp
    from .app import Application

def show_cheat_sheet():
    # case where `git-trac` was just symbolically linked
    root_dir = os.path.dirname(os.path.dirname(__file__))
    cheat_sheet = os.path.join(root_dir, 'doc', 'git-cheat-sheet.pdf')
    # case of `python setup.py install --user`
    if not os.path.exists(cheat_sheet):
        root_dir = __import__('site').USER_BASE
        cheat_sheet = os.path.join(root_dir,
                                   'share',
                                   'git-trac-command',
                                   'git-cheat-sheet.pdf')
    # case of `python setup.py install`
    if not os.path.exists(cheat_sheet):
        root_dir = sys.prefix
        cheat_sheet = os.path.join(root_dir,
                                   'share',
                                   'git-trac-command',
                                   'git-cheat-sheet.pdf')
    # go to internet if not found
    if not os.path.exists(cheat_sheet):
        cheat_sheet = "http://github.com/sagemath/git-trac-command/raw/master/doc/git-cheat-sheet.pdf"
        print('Cheat sheet not found locally. Trying the internet.')
    xdg_open(cheat_sheet)


def debug_shell(app, parser):
    ip = TerminalIPythonApp.instance()
    ip.initialize(argv=[])
    ip.shell.user_global_ns['app'] = app

# Path: git_trac/logger.py
# def make_logger(name, doctest_mode=False):
# def enable_doctest_mode():
# 
# Path: git_trac/ticket_or_branch.py
# class TicketOrBranch(object):
# 
#     def __init__(self, name):
#         self._name = name
#         self._validate()
# 
#     def __int__(self):
#         try:
#             return int(self._name)        
#         except ValueError:
#             pass
# 
#     def __str__(self):
#         return self._name
# 
#     def is_number(self):
#         try:
#             int(self._name)
#             return True
#         except ValueError:
#             return False
# 
#     def is_branch(self):
#         for prefix in ['u/', 'public/']:
#             if self._name.startswith(prefix):
#                 return True
#         if self._name in ['master', 'develop']:
#             return True
#         return False
# 
#     def _validate(self):
#         if self.is_number() or self.is_branch():
#             return
#         raise ValueError('Not a valid ticket number or remote branch name')


# Path: git_trac/cmdline.py
import sys
import os
import warnings
import argparse
    import subprocess
        import importlib
        import logging
from .logger import logger
from .ticket_or_branch import TicketOrBranch
    from IPython.terminal.ipapp import TerminalIPythonApp
    from .app import Application


def show_cheat_sheet():
    # case where `git-trac` was just symbolically linked
    root_dir = os.path.dirname(os.path.dirname(__file__))
    cheat_sheet = os.path.join(root_dir, 'doc', 'git-cheat-sheet.pdf')
    # case of `python setup.py install --user`
    if not os.path.exists(cheat_sheet):
        root_dir = __import__('site').USER_BASE
        cheat_sheet = os.path.join(root_dir,
                                   'share',
                                   'git-trac-command',
                                   'git-cheat-sheet.pdf')
    # case of `python setup.py install`
    if not os.path.exists(cheat_sheet):
        root_dir = sys.prefix
        cheat_sheet = os.path.join(root_dir,
                                   'share',
                                   'git-trac-command',
                                   'git-cheat-sheet.pdf')
    # go to internet if not found
    if not os.path.exists(cheat_sheet):
        cheat_sheet = "http://github.com/sagemath/git-trac-command/raw/master/doc/git-cheat-sheet.pdf"
        print('Cheat sheet not found locally. Trying the internet.')
    xdg_open(cheat_sheet)


def debug_shell(app, parser):
    ip = TerminalIPythonApp.instance()
    ip.initialize(argv=[])
    ip.shell.user_global_ns['app'] = app

    ip.shell.user_global_ns['logger'] = logger