Exemple #1
0
    def _run(self):
        '''
            Entry point for command line call of this program. Determines a \
            meaningful file for running. Set the right code dependent \
            commands and finally executes them.

            Examples:

            >>> sys_argv_backup = sys.argv

            >>> sys.argv[1:] = ['--runner-meta-help', '--log-level', 'info']
            >>> run = Run.run() # doctest: +ELLIPSIS
            usage:...

            >>> empty_folder = FileHandler(
            ...     __test_folder__.path + '_run', make_directory=True)
            >>> sys.argv[1:] = ['-f', empty_folder.path, '--log-level', 'info']
            >>> run = Run.run() # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
            ...
            CodeRunnerError: No supported file path found for running.

            >>> sys.argv = sys_argv_backup
        '''
        command_line_arguments = CommandLine.argument_parser(
            meta=True, arguments=self.COMMAND_LINE_ARGUMENTS,
            module_name=__name__, scope={'self': self})
        if command_line_arguments.meta_help:
            CommandLine.current_argument_parser.print_help()
            return self
        return self._initialize(**self._command_line_arguments_to_dictionary(
            namespace=command_line_arguments))
Exemple #2
0
    def _run(self):
        '''
            Entry point for command line call of this program. Initializes \
            all window and webkit components.

            Examples:

            >>> from copy import copy
            >>> sys_argv_backup = copy(sys.argv)

            >>> sys.argv[1:] = ['google.de']
            >>> Browser.run() # doctest: +ELLIPSIS
            Object of "Browser" with url "http://google.de" in 800 pixel...

            >>> sys.argv = sys_argv_backup
        '''
        return self._initialize(**self._command_line_arguments_to_dictionary(
            namespace=CommandLine.argument_parser(
                module_name=__name__, scope={'self': self},
                arguments=self.COMMAND_LINE_ARGUMENTS)))
Exemple #3
0
    def _run(self):
        '''
            Entry point for command line call of this program. Validates the \
            given input. Gives usage info or raises exception if the given \
            inputs don't make sense.

            Examples:

            >>> from copy import copy
            >>> sys_argv_backup = copy(sys.argv)

            >>> sys.argv[1:] = ['--path', __file_path__, '--skip-self-file']
            >>> Replace.run() # doctest: +ELLIPSIS
            Object of "Replace" with file "..." to convert to "...".

            >>> sys.arv = sys_argv_backup
        '''
        command_line_arguments = CommandLine.argument_parser(
            arguments=self.COMMAND_LINE_ARGUMENTS, module_name=__name__,
            scope={'os': os, 'module_name': __module_name__, 'self': self})
        return self._initialize(**self._command_line_arguments_to_dictionary(
            namespace=command_line_arguments))
Exemple #4
0
# endregion

__all__ = __get_all_modules__()
'''Determine all modules in this folder via introspection.'''

# region footer

'''
    Preset some variables given by introspection letting the linter know what \
    globale variables are available.
'''
__logger__ = __exception__ = __module_name__ = __file_path__ = \
    __test_mode__ = __test_buffer__ = __test_folder__ = __test_globals__ = None
if __name__ == '__main__':
    from boostnode.extension.system import CommandLine
    '''
        Extends this module with some magic environment variables to provide \
        better introspection support. A generic command line interface for \
        some code preprocessing tools is provided by default.
    '''
    CommandLine.generic_package_interface(
        name=__name__, frame=inspect.currentframe())

# endregion

# region vim modline
# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:
# endregion
def main():
    '''Entry point for this script.'''
    global API_DOCUMENTATION_PATH_SUFFIX, CONTENT, SCOPE
    if markdown is None:
        __logger__.critical(
            "You haven't install a suitable markdown version. Documentation "
            "couldn't be updated.")
        return None
    CommandLine.argument_parser(module_name=__name__)
    if '* master' in Platform.run('/usr/bin/env git branch')[
        'standard_output'
    ] and 'gh-pages' in Platform.run('/usr/bin/env git branch --all')[
        'standard_output'
    ]:
        package_file = FileHandler('package.json')
        if package_file.is_file():
            SCOPE = json.loads(package_file.content)
        API_DOCUMENTATION_PATH_SUFFIX = API_DOCUMENTATION_PATH_SUFFIX.format(
            **SCOPE)
        temporary_documentation_folder = FileHandler(
            location=DOCUMENTATION_REPOSITORY[DOCUMENTATION_REPOSITORY.find(
                '/'
            ) + 1:-1])
        if temporary_documentation_folder:
            temporary_documentation_folder.remove_deep()
        __logger__.info('Compile all readme markdown files to html5.')
        FileHandler().iterate_directory(function=add_readme, recursive=True)
        CONTENT = markdown.markdown(
            CONTENT, output='html5',
            extensions=builtins.list(MARKDOWN_EXTENSIONS))
        distribution_bundle_file = create_distribution_bundle_file()
        if distribution_bundle_file is not None:
            data_location = FileHandler(location=DATA_PATH)
            data_location.make_directories()
            distribution_bundle_file.directory = data_location
        has_api_documentation = SCOPE['scripts'].get('document', False)
        if has_api_documentation:
            has_api_documentation = Platform.run(
                '/usr/bin/env yarn document', error=False, log=True
            )['return_code'] == 0
        if Platform.run(
            ('/usr/bin/env git checkout gh-pages', '/usr/bin/env git pull'),
            error=False, log=True
        )['return_code'][0] == 0:
            existing_api_documentation_directory = FileHandler(location='.%s' %
                API_DOCUMENTATION_PATH[1])
            if existing_api_documentation_directory.is_directory():
                existing_api_documentation_directory.remove_deep()
            FileHandler(location=API_DOCUMENTATION_PATH[0]).path = \
                existing_api_documentation_directory
            local_documentation_website_location = FileHandler(
                location='../%s' % temporary_documentation_folder.name)
            if local_documentation_website_location.is_directory():
                temporary_documentation_folder.make_directories()
                local_documentation_website_location.iterate_directory(
                    function=copy_repository_file, recursive=True,
                    source=local_documentation_website_location,
                    target=temporary_documentation_folder)
                node_modules_directory = FileHandler(location='%s%s' % (
                    local_documentation_website_location.path, 'node_modules'))
                if node_modules_directory.is_directory():
                    temporary_documentation_node_modules_directory = \
                        FileHandler('%snode_modules' %
                            temporary_documentation_folder.path)
                    '''
                        NOTE: Symlinking doesn't work since some node modules
                        need the right absolute location to work.

                        node_modules_directory.make_symbolic_link(
                            target='%s%s' % (
                                temporary_documentation_folder, 'node_modules')
                        )
                        return_code = 0

                        NOTE: Coping complete "node_modules" folder takes to
                        long.

                        node_modules_directory.copy(target='%s%s' % (
                            temporary_documentation_folder, 'node_modules'))
                        return_code = 0

                        NOTE: Mounting "node_modules" folder needs root
                        privileges.

                        temporary_documentation_node_modules_directory\
                            .make_directory(right=777)
                        return_code = Platform.run(
                            "/usr/bin/env sudo mount --bind --options ro '%s' "
                            "'%s'" % (
                                node_modules_directory.path,
                                temporary_documentation_node_modules_directory.path
                            ), native_shell=True, error=False, log=True
                        )['return_code']
                    '''
                    return_code = Platform.run(
                        "/usr/bin/env cp --dereference --recursive --reflink=auto '%s' '%s'" % (
                            node_modules_directory.path,
                            temporary_documentation_node_modules_directory.path
                        ),
                        native_shell=True,
                        error=False,
                        log=True
                    )['return_code']
                else:
                    return_code = Platform.run(
                        '/usr/bin/env yarn --production=false',
                        native_shell=True,
                        error=False,
                        log=True
                    )['return_code']
                if return_code == 0:
                    current_working_directory_backup = FileHandler()
                    temporary_documentation_folder.change_working_directory()
                    return_code = Platform.run(
                        '/usr/bin/env yarn clear', native_shell=True,
                        error=False, log=True
                    )['return_code']
                    current_working_directory_backup.change_working_directory()
            else:
                return_code = Platform.run((
                    'unset GIT_WORK_TREE; /usr/bin/env git clone %s;'
                    'yarn --production=false'
                ) % DOCUMENTATION_REPOSITORY, native_shell=True, error=False,
                log=True)['return_code']
            if return_code == 0:
                generate_and_push_new_documentation_page(
                    temporary_documentation_folder,
                    distribution_bundle_file,
                    has_api_documentation,
                    temporary_documentation_node_modules_directory)
            if existing_api_documentation_directory.is_directory():
                existing_api_documentation_directory.remove_deep()