def _handle_collect(self):
     print('Collecting segments:')
     collected_names = []
     for segment_path in self._list_segment_subpackages(
             self._score_package_path):
         source_path = segment_path.joinpath('illustration.ly')
         if not source_path.is_file():
             continue
         collected_names.append(segment_path.name)
         target_path = self._build_path.joinpath(
             'segments',
             datastructuretools.String(segment_path.name).to_dash_case() +
             '.ily')
         contents = self._process_illustration_contents(source_path)
         with open(str(target_path), 'w') as file_pointer:
             file_pointer.write(contents)
         message = '    {!s} --> {!s}'.format(
             source_path.relative_to(self._score_package_path),
             target_path.relative_to(self._score_package_path),
         )
         print(message)
     staged_names = self._read_segments_list_json(self._score_package_path)
     segments_ily_path = self._build_path.joinpath('segments.ily')
     include_template = '    \\include "..{sep}segments{sep}{name}.ily"\n'
     with open(str(segments_ily_path), 'w') as file_pointer:
         file_pointer.write('{\n')
         for name in staged_names:
             if name not in collected_names:
                 continue
             name = datastructuretools.String(name).to_dash_case()
             file_pointer.write(
                 include_template.format(name=name, sep=os.path.sep))
         file_pointer.write('}\n')
Ejemplo n.º 2
0
 def _title_case_name(self):
     return '{}{}In{}'.format(
         datastructuretools.String(
             self.quality_string).to_upper_camel_case(),
         datastructuretools.String(self.extent_name).to_upper_camel_case(),
         datastructuretools.String(self.position).to_upper_camel_case(),
     )
Ejemplo n.º 3
0
 def program_name(self):
     r'''The name of the script, callable from the command line.
     '''
     name = type(self).__name__[:type(self).__name__.rfind('Script')]
     name = datastructuretools.String(name).to_space_delimited_lowercase()
     name = name.replace(' ', '-')
     return name
Ejemplo n.º 4
0
    def __getattr__(self, name):
        r'''Gets arbitrary object keyed to `name`.

        ..  container:: example

            >>> staff = abjad.Staff("c'4 d' e' f'")
            >>> abjad.setting(staff).instrument_name = abjad.Markup('Vn. I')
            >>> abjad.show(staff) # doctest: +SKIP

            ..  docs::

                >>> abjad.f(staff)
                \new Staff
                \with
                {
                    instrumentName = \markup { "Vn. I" }
                }
                {
                    c'4
                    d'4
                    e'4
                    f'4
                }

        ..  container:: example

            Returns arbitrary object keyed to `name`:

            >>> abjad.setting(staff).instrument_name
            Markup(contents=['Vn. I'])

        '''
        from abjad import ly
        from abjad.tools import lilypondnametools
        camel_name = datastructuretools.String(name).to_upper_camel_case()
        if name.startswith('_'):
            try:
                return vars(self)[name]
            except KeyError:
                message = '{!r} object has no attribute: {!r}.'
                message = message.format(type(self).__name__, name)
                raise AttributeError(message)
        elif camel_name in ly.contexts:
            try:
                return vars(self)['_' + name]
            except KeyError:
                context = lilypondnametools.LilyPondNameManager()
                vars(self)['_' + name] = context
                return context
        else:
            try:
                return vars(self)[name]
            except KeyError:
                message = '{!r} object has no attribute: {!r}.'
                message = message.format(type(self).__name__, name)
                raise AttributeError(message)
Ejemplo n.º 5
0
 def _handle_create(
     self,
     target_name,
     force,
     paper_size=None,
     orientation=None,
 ):
     from abjad import abjad_configuration
     if target_name is True:
         name = paper_size.lower().replace(' ', '-')
         name = '{}-{}'.format(name, orientation)
     else:
         name = datastructuretools.String(target_name).to_dash_case()
     dimensions = self.paper_sizes[paper_size]
     message = 'Creating build target {!r} ({}{} x {}{})'.format(
         name,
         dimensions[0][0],
         dimensions[0][1],
         dimensions[1][0],
         dimensions[1][1],
     )
     print(message)
     target_path = self._name_to_score_subdirectory(
         name, 'builds', self._score_package_path)
     if target_path.exists() and not force:
         print('    Path exists: {!s}'.format(
             target_path.relative_to(self._score_package_path.parent)))
         sys.exit(1)
     metadata = self._read_score_metadata_json(self._score_package_path)
     metadata['score_package_name'] = self._score_package_path.name
     if orientation == 'portrait':
         rotation = 0
         width, height = self.paper_sizes[paper_size]
     else:
         rotation = -90
         height, width = self.paper_sizes[paper_size]
     metadata['rotation'] = rotation
     metadata['orientation'] = orientation
     metadata['paper_size'] = paper_size
     metadata['height'] = height[0]
     metadata['width'] = width[0]
     metadata['unit'] = height[1]
     metadata['global_staff_size'] = 12
     metadata['uppercase_composer_name'] = metadata['composer_name'].upper()
     metadata['uppercase_title'] = metadata['title'].upper()
     metadata['lilypond_version'] = \
         abjad_configuration.get_lilypond_version_string()
     source_name = 'build'
     source_path = self._get_boilerplate_path().joinpath(source_name)
     suffixes = ('.py', '.tex', '.ly', '.ily')
     for path in self._copy_tree(source_path, target_path):
         if path.is_file() and path.suffix in suffixes:
             self._template_file(path, **metadata)
     print('    Created {!s}'.format(
         target_path.relative_to(self._score_repository_path)))
Ejemplo n.º 6
0
 def _report_time(self, timer, prefix='Runtime'):
     message = '        {}: {} {}'
     total_time = int(timer.elapsed_time)
     identifier = datastructuretools.String('second').pluralize(total_time)
     message = message.format(prefix, total_time, identifier)
     print(message)
Ejemplo n.º 7
0
 def _name_to_score_subdirectory(self, name, section, score_path):
     score_path = self._path_to_score_package_path(score_path)
     name = datastructuretools.String(name).to_accent_free_snake_case()
     path = score_path.joinpath(section, name)
     return path
Ejemplo n.º 8
0
 def _handle_create(
     self,
     title,
     year,
     composer_email=None,
     composer_github=None,
     composer_library=None,
     composer_name=None,
     composer_website=None,
     force=False,
 ):
     print('Creating score package {!r}...'.format(title))
     score_package_name = datastructuretools.String(title)
     score_package_name = score_package_name.to_accent_free_snake_case()
     outer_target_path = pathlib.Path(score_package_name).absolute()
     inner_target_path = outer_target_path.joinpath(score_package_name)
     if outer_target_path.exists() and not force:
         message = '    Directory {!s} already exists.'
         message = message.format(score_package_name)
         print(message)
         sys.exit(1)
     metadata = {
         'score_package_name': score_package_name,
         'composer_email': composer_email,
         'composer_full_name': composer_name,
         'composer_github_username': composer_github,
         'composer_library_package_name': composer_library,
         'score_title': title,
         'year': year,
     }
     boilerplate_path = self._get_boilerplate_path()
     outer_source_path = boilerplate_path.joinpath('score')
     inner_source_path = outer_source_path.joinpath('score')
     suffixes = ('.py', '.tex', '.ly', '.ily', '.md', '.yml')
     for path in self._copy_tree(
             outer_source_path,
             outer_target_path,
             recurse=False,
     ):
         if path.is_file() and path.suffix in suffixes:
             self._template_file(path, **metadata)
     for path in self._copy_tree(
             inner_source_path,
             inner_target_path,
             recurse=True,
     ):
         if path.is_file() and path.suffix in suffixes:
             self._template_file(path, **metadata)
     self._setup_paths(inner_target_path)
     self._write_json(
         dict(
             composer_email=composer_email,
             composer_github=composer_github,
             composer_library=composer_library,
             composer_name=composer_name,
             composer_website=composer_website,
             title=title,
             year=int(year),
         ),
         inner_target_path.joinpath('metadata.json'),
     )
     print('    Created {path!s}{sep}'.format(path=score_package_name,
                                              sep=os.path.sep))