Exemple #1
0
    def execute(self, args):
        super(NgrokStart, self).execute(args)

        env_with_path = dict(os.environ)
        env_with_path['PATH'] += '%s%s' % (os.pathsep,
                                           os.path.expanduser(args.path))
        if args.named_tunnel:
            return Executable('ngrok', verbose=True).check_call(
                ['start', '--region=%s' % args.region] + args.named_tunnel,
                env=env_with_path)
        else:
            if args.vagrant:
                vagrant_ssh_config = VagrantMachine(
                    args.vagrant).get_ssh_config()
                hostname = vagrant_ssh_config['HostName']
                port = vagrant_ssh_config['Port']
            elif args.ssh:
                hostname = args.ssh
                port = args.port
            else:
                hostname = None
                port = args.port

            hostname_port = ':'.join([i for i in [hostname, port] if i])
            return Executable('ngrok', verbose=True).check_call(
                ['tcp', '--region=%s' % args.region, hostname_port],
                env=env_with_path)
Exemple #2
0
 def create_database(self, super_user_name=None):
     Executable('mysqladmin').check_call(['create'] + self.login_args(
         login_username=super_user_name) + [self.database_name])
     if self.user_name:
         Executable('mysql').check_call(
             self.login_args(login_username=super_user_name) + [
                 '-e',
                 'grant all privileges on %s.* to %s;' %
                 (self.database_name, self.user_name)
             ])
     Executable('mysqladmin').check_call(
         ['flush-privileges'] +
         self.login_args(login_username=super_user_name))
     return 0
Exemple #3
0
 def restore_all_databases(self, filename):
     with closing(gzip.open(filename, 'rb')) as zipped_file:
         proc = Executable('psql').Popen(['-d', 'template1'],
                                         stdin=subprocess.PIPE)
         for line in zipped_file:
             proc.stdin.write(line)
     return 0
Exemple #4
0
def model_examples(fixture):
    # These examples are built to run outside of our infrastructure, hence have to be run like this:
    for example in ['modeltests1.py', 'modeltests2.py', 'modeltests3.py']:
        Executable('nosetests').check_call([
            '--first-package-wins',
            'reahl/doc/examples/tutorial/%s' % example
        ])
Exemple #5
0
 def execute(self, args):
     super().execute(args)
     self.git = Executable('git')
     for filename in self.get_all_filenames():
         if os.path.splitext(filename)[1] not in ['.mo', '.png', '.jpg']:
             self.process_file(filename, args.copyright_holder_string)
     return 0
Exemple #6
0
 def create_db_user(self, super_user_name=None, create_with_password=True):
     create_password_option = 'P' if create_with_password else ''
     with as_domain_exception(ExecutableNotInstalledException):
         Executable('createuser').check_call(['-DSRl%s' % create_password_option]
                                             + self.login_args(login_username=super_user_name)
                                             + [self.user_name])
     return 0
Exemple #7
0
    def drop_database(self, yes=False):
        cmd_args = self.login_args
        last_part = ['-i', self.database_name]
        if yes:
            last_part = [self.database_name]

        Executable('dropdb').check_call(cmd_args + last_part)
        return 0
Exemple #8
0
 def restore_all_databases(self, filename, super_user_name=None):
     with closing(gzip.open(filename, 'rb')) as zipped_file:
         with as_domain_exception(ExecutableNotInstalledException):
             proc = Executable('psql').Popen(self.login_args(login_username=super_user_name)
                                             + ['-d', 'postgres'], stdin=subprocess.PIPE)
         for line in zipped_file:
             proc.stdin.write(line)
     return 0
Exemple #9
0
    def drop_database(self, super_user_name=None, yes=False):
        cmd_args = self.login_args(login_username=super_user_name)
        if yes:
            cmd_args.append('-f')

        Executable('mysqladmin').check_call(['drop'] + cmd_args +
                                            [self.database_name])
        return 0
Exemple #10
0
 def restore_all_databases(self, filename, super_user_name=None):
     with closing(gzip.open(filename, 'rb')) as zipped_file:
         proc = Executable('mysql').Popen(
             self.login_args(login_username=super_user_name),
             stdin=subprocess.PIPE)
         for line in zipped_file:
             proc.stdin.write(line)
     return 0
Exemple #11
0
 def create_database(self, super_user_name=None):
     owner_option = ['-O', self.user_name] if self.user_name else []
     with as_domain_exception(ExecutableNotInstalledException):
         Executable('createdb').check_call(['-Eunicode']
                                           + self.login_args(login_username=super_user_name)
                                           + ['-T', 'template0']
                                           + owner_option + [self.database_name])
     return 0
Exemple #12
0
 def ssh_config_file(self):
     try:
         with tempfile.NamedTemporaryFile('w', delete=False) as ssh_config:
             Executable('vagrant').check_call(
                 ['ssh-config', self.machine_name], stdout=ssh_config)
         yield ssh_config
     finally:
         os.remove(ssh_config.name)
Exemple #13
0
 def backup_database(self, directory):
     today = date.today()
     filename = '%s.psql.%s' % (self.database_name, today.strftime('%A'))
     full_path = os.path.join(directory, filename)
     with io.open(full_path, 'w') as destination_file:
         cmd_args = ['-Fc', '-o'] + self.login_args + [self.database_name]
         Executable('pg_dump').check_call(cmd_args, stdout=destination_file)
     return 0
Exemple #14
0
    def function(self, project, args):
        @contextmanager
        def nop_context_manager():
            yield

        context_manager = project.generated_setup_py if args.generate_setup_py else nop_context_manager
        with context_manager():
            command = self.do_shell_expansions(project.directory, args.shell_commandline)
            return Executable(command[0]).call(command[1:], cwd=project.directory)
Exemple #15
0
 def backup_database(self, directory, super_user_name=None):
     today = date.today()
     filename = '%s.psql.%s' % (self.database_name, today.strftime('%A'))
     full_path = os.path.join(directory, filename)
     with io.open(full_path, 'w') as destination_file:
         cmd_args = ['-Fc', '-o'] + self.login_args(login_username=super_user_name) + [self.database_name]
         with as_domain_exception(ExecutableNotInstalledException):
             Executable('pg_dump').check_call(cmd_args, stdout=destination_file)
     return 0
Exemple #16
0
    def drop_database(self, super_user_name=None, yes=False):
        cmd_args = self.login_args(login_username=super_user_name) + ['--if-exists']
        last_part = ['-i', self.database_name]
        if yes:
            last_part = [self.database_name]

        with as_domain_exception(ExecutableNotInstalledException):
            Executable('dropdb').check_call(cmd_args + last_part)
        return 0
Exemple #17
0
 def new_git_directory(self, initialised=True):
     git_directory = temp_dir()
     if initialised:
         with open(os.devnull, 'w') as DEVNULL:
             Executable('git').check_call(['init'],
                                          cwd=git_directory.name,
                                          stdout=DEVNULL,
                                          stderr=DEVNULL)
     return git_directory
Exemple #18
0
 def create_db_user(self, super_user_name=None, create_with_password=True):
     super().create_db_user(super_user_name=super_user_name,
                            create_with_password=create_with_password)
     identified = 'by \'%s\'' % self.password if create_with_password else 'with \'auth_sock\''
     Executable('mysql').check_call(
         self.login_args(login_username=super_user_name) + [
             '-e',
             'create user %s identified %s;' % (self.user_name, identified)
         ])
     return 0
Exemple #19
0
 def function(self, project, options, args):
     if not args:
         raise Exception(
             'You have to supply the destination of the push as <target_spec>'
         )
     return Executable('devpi').check_call([
         'push',
         '%s-%s' %
         (project.project_name, project.version_for_setup()), args[0]
     ],
                                           cwd=project.directory)
Exemple #20
0
 def backup_database(self, directory, super_user_name=None):
     today = date.today()
     filename = '%s.%s.sql.gz' % (self.database_name, today.strftime('%A'))
     full_path = os.path.join(directory, filename)
     with closing(gzip.open(full_path, 'wb')) as zipped_file:
         proc = Executable('mysqldump').Popen(
             self.login_args(login_username=super_user_name) +
             [self.database_name],
             stdout=subprocess.PIPE)
         for line in proc.stdout:
             zipped_file.write(line)
     return 0
Exemple #21
0
 def do_shell_expansions(self, directory, commandline):
     replaced_command = []
     for i in commandline:
         if i.startswith('$(') and i.endswith(')'):
             shellcommand = i[2]
             shell_args = i[3:-1].split(' ')
             output = Executable(shellcommand).Popen(shell_args, cwd=directory, stdout=subprocess.PIPE).communicate()[0]
             for line in output.splitlines():
                 replaced_command.append(line)
         else:
             replaced_command.append(i)
     return replaced_command
Exemple #22
0
    def execute(self, args):
        super().execute(args)
        self.sitecopy = Executable('sitecopy')

        try:
            site_name = args.site_name or self.get_site_name()
            local_info_file = os.path.expanduser(os.path.join('~', '.sitecopy', site_name))
            if args.fetch_first or not os.path.exists(local_info_file):
                if os.path.exists(local_info_file):
                    os.remove(local_info_file)
                self.sitecopy.check_call('-r sitecopy.rc --fetch'.split()+[site_name])
            self.sitecopy.check_call('-r sitecopy.rc --update'.split()+[site_name])
        except subprocess.CalledProcessError as ex:
            raise DomainException(message='Running "%s" failed with exit code %s' % (' '.join(ex.cmd), ex.returncode))
Exemple #23
0
    def function(self, project, options, args):
        if not args:
            print('No shell command specified to run', file=sys.stderr)
            return 1

        @contextmanager
        def nop_context_manager():
            yield

        context_manager = project.generated_setup_py if options.generate_setup_py else nop_context_manager
        with context_manager():
            command = self.do_shell_expansions(project.directory, args)
            return Executable(command[0]).call(command[1:],
                                               cwd=project.directory)
Exemple #24
0
    def backup_all_databases(self, directory):
        today = date.today()
        hostname = self.host
        if hostname == 'localhost':
            hostname = socket.gethostname()
        filename = '%s-all.%s.sql.gz' % (hostname, today.strftime('%A'))
        full_path = os.path.join(directory, filename)

        with closing(gzip.open(full_path, 'wb')) as zipped_file:
            proc = Executable('pg_dumpall').Popen(['-o'] + self.login_args,
                                                  stdout=subprocess.PIPE)
            for line in proc.stdout:
                zipped_file.write(line)
        return 0
Exemple #25
0
 def new_chrome_options(self):
     from selenium.webdriver.chrome.options import Options
     options = Options()
     options.add_argument('--disable-preconnect')
     options.add_argument('--dns-prefetch-disable')
     #        options.add_argument('--start-maximized')  # This breaks xpra pair programming currently.
     options.add_argument(
         '--no-sandbox'
     )  # Needed to be able to run a user-installed version of chromium on travis
     options.binary_location = Executable(
         'chromium-browser'
     ).executable_file  # To run a custom-installed chromium as picked up by the PATH
     #--enable-http-pipelining
     #--learning
     #--single-process
     return options
Exemple #26
0
    def execute(self, args):
        project = Project.from_file(self.workspace,
                                    self.workspace.startup_directory)
        with project.paths_set():
            try:
                if args.restart:
                    ServerSupervisor(sys.argv[1:] + ['--dont-restart'],
                                     args.max_seconds_between_restarts,
                                     ['.'] + args.monitored_directories).run()
                else:
                    config_directory = args.config_directory
                    six.print_('\nUsing config from %s\n' % config_directory,
                               flush=True)

                    try:
                        reahl_server = ReahlWebServer.fromConfigDirectory(
                            config_directory, args.port)
                    except pkg_resources.DistributionNotFound as ex:
                        terminate_keys = 'Ctrl+Break' if platform.system(
                        ) == 'Windows' else 'Ctrl+C'
                        six.print_('\nPress %s to terminate\n\n' %
                                   terminate_keys,
                                   flush=True)
                        raise CouldNotConfigureServer(ex)

                    reahl_server.start(connect=True)
                    six.print_('\n\nServing http on port %s, https on port %s (config=%s, flush=True)' % \
                                     (args.port, args.port+363, config_directory))
                    terminate_keys = 'Ctrl+Break' if platform.system(
                    ) == 'Windows' else 'Ctrl+C'
                    six.print_('\nPress %s to terminate\n\n' % terminate_keys,
                               flush=True)

                    notify = Executable('notify-send')
                    try:
                        notify.call(['Reahl', 'Server restarted'])
                    except:
                        pass

                    reahl_server.wait_for_server_to_complete()
            except KeyboardInterrupt:
                six.print_('\nShutting down', flush=True)
            except CouldNotConfigureServer as ex:
                six.print_(ex, flush=True)
        return 0
Exemple #27
0
    def create_files(self):
        control_file_contents = """Section: misc
Priority: optional
Standards-Version: 3.6.2

Package: equivs-dummy
Version: 1.0
Maintainer: %s <%s>
Architecture: all
Description: some wise words 
 long description and info
 .
 second paragraph

""" % (os.environ['DEBFULLNAME'], os.environ['EMAIL'])
        self.temp_directory.file_with('control', control_file_contents)
        Executable('equivs-build').check_call(['-a', 'i386', '-f', 'control'],
                                              cwd=self.temp_directory.name)
Exemple #28
0
 def restore_database(self, filename, super_user_name=None):
     with as_domain_exception(ExecutableNotInstalledException):
         Executable('pg_restore').check_call(
             self.login_args(login_username=super_user_name) +
             ['-C', '-Fc', '-d', 'postgres', filename])
     return 0
Exemple #29
0
 def __init__(self, xpra_executable=None, ssh_executable=None):
     self.xpra_executable = xpra_executable or Executable('xpra',
                                                          verbose=True)
     self.ssh_executable = ssh_executable or Executable('ssh', verbose=True)
Exemple #30
0
 def drop_db_user(self, super_user_name=None):
     with as_domain_exception(ExecutableNotInstalledException):
         Executable('dropuser').check_call(self.login_args(login_username=super_user_name) + [self.user_name])
     return 0