Exemple #1
0
def change_hosts(filename):
    try:
        if os_resolver() != 'Windows':
            if os.getuid() == 0:
                proc = subprocess.call(['cp', filename, hosts_path()])
            else:
                logger().warning('You don\'t have root privileges.')
                proc = subprocess.call(['sudo', 'cp', filename, hosts_path()])
        elif os_resolver() == 'Windows':
            proc = os.system("xcopy \"" + filename + "\"  \"" + hosts_path() +
                             "\" /F /Y")
        if proc != 0:
            raise SystemExit('Can\'t access to system hosts file.\nExit')
    except OSError as e:
        logger().error(e)
Exemple #2
0
    def __init__(self, args):
        self.args = args
        self.name = self.args['name'][0]
        self.log = logger()

        self.__remove_hosts_file()
        self.__print_response()
Exemple #3
0
    def __init__(self, args):
        self.args = args
        self.hosts_path = self.args['hosts_path']
        self.log = logger()

        titles = ['File name', 'Create date', 'Update date']
        table.print_table(titles, self.in_use(self.list_of_file()['list']))
Exemple #4
0
 def __init__(self, args):
     self.args = args
     self.log = logger()
     self.sys_hosts_path = hostswitcher.lib.hosts_path()
     self.file_name = 'default'
     self.copy_current_host_file()
     self.__print_response()
Exemple #5
0
    def __init__(self, args):
        self.args = args
        self.name = self.args['name'][0]
        self.log = logger()
        self.origin = self.args['from']

        self.create_new_file()
        self.__print_response()
Exemple #6
0
    def __init__(self, args):
        self.args = args
        self.sys_hosts_path = hostswitcher.lib.hosts_path()
        self.name = self.args['name']
        self.log = logger()

        self.__set_file()
        self.__print_response()
Exemple #7
0
    def __init__(self, args):
        self.args = args
        # self.hosts_file_suffix= 'combined'
        # self.name = '%s.%s' % (self.args['name'][0], self.hosts_file_suffix)
        self.name = self.args['name'][0]
        self.origin = self.args['from']
        self.log = logger()

        self.__combine()
        self.__print_response()
Exemple #8
0
class Hostswitcher(object):

    title = '''
        ╦ ╦╔═╗╔═╗╔╦╗  ╔═╗╦ ╦╦╔╦╗╔═╗╦ ╦╔═╗╦═╗
        ╠═╣║ ║╚═╗ ║───╚═╗║║║║ ║ ║  ╠═╣║╣ ╠╦╝
        ╩ ╩╚═╝╚═╝ ╩   ╚═╝╚╩╝╩ ╩ ╚═╝╩ ╩╚═╝╩╚═
        '''

    log = logger()

    def __init__(self):
        self.__print_title()
        self.__hosts_path()
        self.__start_cli()

    def __print_title(self):
        print(self.title)
        print('Version: %s' % (__version__))
        print('OS: %s' % (os_resolver()), end='\n\n')

    def __start_cli(self):
        self.cli = cli()
        self.args = self.cli.args()

    def __hosts_path(self):

        homedir = os.path.expanduser("~")

        if os_resolver() == 'Windows':
            homedir += "\\AppData\\Roaming"

        self.hosts_path = os.path.join(homedir, '.hostswitcher/hosts_files')
        create_path(self.hosts_path)

    def run(self):
        from hostswitcher.cli import commands
        class_ = getattr(commands, self.args['command'])
        self.args['hosts_path'] = self.hosts_path
        cmd = class_(self.args)