Exemplo n.º 1
0
def bootstrap_workspace(workspace_dir, core_project_dirs):
    make_core_projects_importable(core_project_dirs)
    from reahl.dev.devdomain import Project, Workspace
    workspace = Workspace(workspace_dir)
    for project_dir in core_project_dirs:
        Project.from_file(workspace, os.path.join(os.getcwd(), project_dir))

    core_projects = [Project.from_file(workspace, os.path.join(os.getcwd(), project_dir)) for project_dir in core_project_dirs]
    return workspace, core_projects
Exemplo n.º 2
0
    def execute(self, options, args):
        if options.states or options.tags:
            project_list = self.workspace.get_selection_subset(
                states=options.states,
                tags=options.tags,
                append=False,
                all_=options.all,
                negated=options.negated)
        elif options.selection:
            project_list = self.workspace.selection
        else:
            project_list = ProjectList(self.workspace)
            try:
                current_project = self.workspace.project_in(os.getcwd())
            except ProjectNotFound:
                try:
                    current_project = Project.from_file(
                        self.workspace, os.getcwd())
                except NotAValidProjectException:
                    current_project = Project(self.workspace, os.getcwd())
            project_list.append(current_project)

        pause = options.pause
        summary = options.summary
        delimit_output = options.delimit_output

        results = {}
        for i in project_list:
            if delimit_output:
                print('\n--- START %s %s ---' %
                      (i.relative_directory, ' '.join(args)))
            results[i] = self.execute_one(i, options, args)
            if pause:
                print('--- PAUSED, hit <enter> to continue, ^D to stop ---')
                if not sys.stdin.readline():
                    print('\n^D pressed, halting immediately')
                    break
            if delimit_output:
                print('--- END %s %s ---' %
                      (i.relative_directory, ' '.join(args)))

        if summary:
            print('\n--- SUMMARY ---')
            for i in project_list:
                print('%s %s' % (results[i], i.relative_directory),
                      file=sys.stdout)
            print('--- END ---\n')

        success = set(results.values()) == {0}
        status_message = '' if success else '(despite failures)'
        print('Performing post command duties %s' % status_message)
        self.perform_post_command_duties()

        if success:
            return 0
        return -1
Exemplo n.º 3
0
    def execute(self, args):
        if args.states or args.tags:
            project_list = self.workspace.get_selection_subset(
                states=args.states,
                tags=args.tags,
                append=False,
                all_=args.all,
                negated=args.negated)
        elif args.selection:
            project_list = self.workspace.selection
        else:
            project_list = ProjectList(self.workspace)
            try:
                current_project = self.workspace.project_in(os.getcwd())
            except ProjectNotFound:
                try:
                    current_project = Project.from_file(
                        self.workspace, os.getcwd())
                except NotAValidProjectException:
                    current_project = Project(self.workspace, os.getcwd())
            project_list.append(current_project)

        pause = args.pause
        summary = args.summary
        delimit_output = args.delimit_output

        results = {}
        for i in project_list:
            if delimit_output:
                print(
                    self.format_individual_message(i, args,
                                                   '\n--- START %s ---'))
            results[i] = self.execute_one(i, args)
            if pause:
                print('--- PAUSED, hit <enter> to continue, ^D to stop ---')
                if not sys.stdin.readline():
                    print('\n^D pressed, halting immediately')
                    break
            if delimit_output:
                print(
                    self.format_individual_message(i, args,
                                                   '\n--- END %s ---'))

        if summary:
            print('\n--- SUMMARY ---')
            for i in project_list:
                print('%s %s' % (results[i], i.relative_directory),
                      file=sys.stdout)
            print('--- END ---\n')

        success = set(results.values()) == {0}
        if success:
            return 0
        return 1
Exemplo n.º 4
0
def test_egg_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')
    @stubclass(Workspace)
    class WorkspaceStub(object):
        directory = workspace_dir.name
    workspace = WorkspaceStub()

    # Case where the file exists with stuff in it
    xml_file = project_dir.file_with('.reahlproject', '''
<project type="egg" basket="some-basket">
<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
<sshdirectory host="localhost2" login="******" destination="/a/c"/>
</distpackage>
</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    assert isinstance(project, EggProject)
    assert project.basket_name == 'some-basket'

    [package] = project.packages_to_distribute
    assert isinstance(package, DebianPackage)
    assert package.project is project

    [repository1, repository2] = package.repositories
    assert repository1.host == 'localhost1'
    assert repository1.login == os.environ.get('USER', '')
    assert repository1.destination == '/a/b'
    assert repository2.host == 'localhost2'
    assert repository2.login == 'someusername'
    assert repository2.destination == '/a/c'
Exemplo n.º 5
0
def test_generic_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')

    @stubclass(Workspace)
    class WorkspaceStub:
        directory = workspace_dir.name

    workspace = WorkspaceStub()

    # Case where the file does not exist
    assert not os.path.exists(project_filename)
    with expected(NotAValidProjectException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists, but is empty
    xml_file = project_dir.file_with('.reahlproject', '')
    with expected(InvalidProjectFileException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists with stuff in it
    del xml_file
    xml_file = project_dir.file_with(
        '.reahlproject', '''
<project type="egg">
<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
<sshdirectory host="localhost2" login="******" destination="/a/c"/>
</distpackage>
</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    assert isinstance(project, Project)

    [package] = project.packages_to_distribute
    assert isinstance(package, DebianPackage)
    assert package.project is project

    [repository1, repository2] = package.repositories
    assert repository1.host == 'localhost1'
    assert repository1.login == os.environ.get('USER', '')
    assert repository1.destination == '/a/b'
    assert repository2.host == 'localhost2'
    assert repository2.login == 'someusername'
    assert repository2.destination == '/a/c'
Exemplo n.º 6
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
Exemplo n.º 7
0
def test_setup_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')
    project_source = project_dir.sub_dir('this')
    project_source_init = project_source.file_with('__init__.py', '')
    project_package1 = project_source.sub_dir('pack1')
    project_package1_init = project_package1.file_with('__init__.py', '')
    project_package2 = project_source.sub_dir('pack2')
    project_package2_init = project_package2.file_with('__init__.py', '')
    project_egg = project_dir.file_with('projegg.py', '')
    project_dev = project_source.sub_dir('proj_dev')

    @stubclass(Project)
    class ProjectStub:
        version = VersionNumber('1.2.5')

    @stubclass(Workspace)
    class WorkspaceStub:
        directory = workspace_dir.name
        project_name = 'proj'
        projects = []

        def project_named(self, name):
            return ProjectStub()

        def has_project_named(self, name):
            return True

    workspace = WorkspaceStub()

    # Case where the file does not exist
    assert not os.path.exists(project_filename)
    with expected(NotAValidProjectException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists, but is empty
    xml_file = project_dir.file_with('.reahlproject', '')
    with expected(InvalidProjectFileException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists with stuff in it
    del xml_file
    xml_file = project_dir.file_with(
        '.reahlproject', '''
<project type="egg" packagedata="included">
<namespaces>
<package name="this"/>
</namespaces>

<tag name="sometag"/>

<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
</distpackage>

<version number="0.0">
  <deps purpose="run">
    <egg name="reahl-xmlreader-run"/>
  </deps>
</version>

<deps purpose="test">
<egg name="reahl-xmlreader-test"/>
</deps>

<deps purpose="build">
<egg name="reahl-xmlreader-build"/>
</deps>

<script name="script1" locator="some script"/>
<script name="script2" locator="some other script"/>

<export entrypoint="entrypoint name 1" name="name1" locator="locator1"/>
<export entrypoint="entrypoint name 2" name="name2" locator="locator2"/>

<excludepackage name="this.pack2"/>

<pythonpath path="stuff"/>
<pythonpath path="stuff2"/>

</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    # Default Metadata queries that will com for setup.py:
    assert project.project_name == os.path.basename(project_dir.name)
    assert str(project.version) == '0.0'

    @stubclass(ProjectMetadata)
    class MetadataStub:
        @property
        def version(self):
            return VersionNumber('3.1.2a1-ubuntu1')

        @property
        def project_name(self):
            return 'test-proj'

    project.metadata = MetadataStub()
    assert str(project.version_for_setup()) == '3.1.2a1'
    assert project.project_name == 'test-proj'

    packages = project.packages_for_setup()
    assert packages == ['this', 'this.pack1']
    assert project.py_modules_for_setup() == []
    assert project.include_package_data == True
    assert project.namespace_packages_for_setup() == ['this']

    expected_value = ['reahl-xmlreader-run>=1.2,<1.3']
    actual = project.run_deps_for_setup()
    assert actual == expected_value

    expected_value = ['reahl-xmlreader-test>=1.2,<1.3']
    actual = project.test_deps_for_setup()
    assert actual == expected_value

    expected_value = ['reahl-xmlreader-build>=1.2,<1.3']
    actual = project.build_deps_for_setup()
    assert actual == expected_value

    assert project.test_suite_for_setup() == 'this.proj_dev'

    expected_value = {
        'console_scripts':
        ['script1 = some script', 'script2 = some other script'],
        'entrypoint name 2': ['name2 = locator2'],
        'reahl.eggs': ['Egg = reahl.component.eggs:ReahlEgg'],
        'entrypoint name 1': ['name1 = locator1'],
        'reahl.versiondeps.0.0': ['reahl-xmlreader-run = egg:_'],
        'reahl.versions': ['0.0 = 0.0']
    }

    assert project.entry_points_for_setup() == expected_value

    assert project.python_path == ['stuff', 'stuff2']

    assert project.tags == ['sometag', 'component', 'toplevel']