Example #1
0
 def preprocess_data(cls, data, element):
     data['metadata'] = {}
     data['entities'] = {}
     for key in (
         'aliases',
         'groups',
         'members',
         'parent_label',
         'sublabels',
         ):
         if key in data:
             data['entities'][key] = data.pop(key)
     for key in (
         'contact_info',
         'name_variations',
         'profile',
         'real_name',
         'urls',
         ):
         if key in data:
             data['metadata'][key] = data.pop(key)
     if 'name' in data and data.get('name'):
         search_content = data.get('name')
         search_content = search_content.lower()
         search_content = stringtools.strip_diacritics(search_content)
         data['search_content'] = peewee.fn.to_tsvector(search_content)
     if element.tag == 'artist':
         data['entity_type'] = 1
     elif element.tag == 'label':
         data['entity_type'] = 2
     return data
Example #2
0
 def _make_file(
     self, 
     extension=None, 
     message='file name', 
     ):
     from scoremanager import idetools
     extension = extension or getattr(self, '_extension', '')
     if self._session.is_in_score:
         path = self._get_current_directory()
     else:
         path = self._select_storehouse_path()
         if self._session.is_backtracking or path is None:
             return
     getter = self._io_manager._make_getter()
     getter.append_string(message)
     name = getter._run()
     if self._session.is_backtracking or name is None:
         return
     name = stringtools.strip_diacritics(name)
     if hasattr(self, '_file_name_callback'):
         name = self._file_name_callback(name)
     name = name.replace(' ', '_')
     if self._force_lowercase:
         name = name.lower()
     if not name.endswith(extension):
         name = name + extension
     path = os.path.join(path, name)
     self._io_manager.write(path, '')
     self._io_manager.edit(path)
Example #3
0
 def _get_available_path(
     self,
     message=None,
     storehouse_path=None,
     ):
     storehouse_path = storehouse_path or self._current_storehouse_path
     while True:
         default_prompt = 'enter {} name'.format(self._asset_identifier)
         message = message or default_prompt
         getter = self._io_manager._make_getter()
         getter.append_string(message)
         name = getter._run()
         if self._session.is_backtracking or not name:
             return
         name = stringtools.strip_diacritics(name)
         words = stringtools.delimit_words(name)
         words = [_.lower() for _ in words]
         name = '_'.join(words)
         if not stringtools.is_snake_case_package_name(name):
             continue
         path = os.path.join(storehouse_path, name)
         if os.path.exists(path):
             line = 'path already exists: {!r}.'
             line = line.format(path)
             self._io_manager._display(line)
         else:
             return path
Example #4
0
 def preprocess_data(cls, data, element):
     data['metadata'] = {}
     data['entities'] = {}
     for key in (
         'aliases',
         'groups',
         'members',
         'parent_label',
         'sublabels',
         ):
         if key in data:
             data['entities'][key] = data.pop(key)
     for key in (
         'contact_info',
         'name_variations',
         'profile',
         'real_name',
         'urls',
         ):
         if key in data:
             data['metadata'][key] = data.pop(key)
     if 'name' in data and data.get('name'):
         search_content = data.get('name')
         search_content = search_content.lower()
         search_content = stringtools.strip_diacritics(search_content)
         data['search_content'] = peewee.fn.to_tsvector(search_content)
     if element.tag == 'artist':
         data['entity_type'] = 1
     elif element.tag == 'label':
         data['entity_type'] = 2
     return data
Example #5
0
 def _make_file(
     self,
     extension=None,
     message='file name',
 ):
     from scoremanager import idetools
     extension = extension or getattr(self, '_extension', '')
     if self._session.is_in_score:
         path = self._get_current_directory()
     else:
         path = self._select_storehouse_path()
         if self._session.is_backtracking or path is None:
             return
     getter = self._io_manager._make_getter()
     getter.append_string(message)
     name = getter._run()
     if self._session.is_backtracking or name is None:
         return
     name = stringtools.strip_diacritics(name)
     if hasattr(self, '_file_name_callback'):
         name = self._file_name_callback(name)
     name = name.replace(' ', '_')
     if self._force_lowercase:
         name = name.lower()
     if not name.endswith(extension):
         name = name + extension
     path = os.path.join(path, name)
     self._io_manager.write(path, '')
     self._io_manager.edit(path)
Example #6
0
 def _get_available_path(
     self,
     message=None,
     storehouse_path=None,
 ):
     storehouse_path = storehouse_path or self._current_storehouse_path
     while True:
         default_prompt = 'enter {} name'.format(self._asset_identifier)
         message = message or default_prompt
         getter = self._io_manager._make_getter()
         getter.append_string(message)
         name = getter._run()
         if self._session.is_backtracking or not name:
             return
         name = stringtools.strip_diacritics(name)
         words = stringtools.delimit_words(name)
         words = [_.lower() for _ in words]
         name = '_'.join(words)
         if not stringtools.is_snake_case_package_name(name):
             continue
         path = os.path.join(storehouse_path, name)
         if os.path.exists(path):
             line = 'path already exists: {!r}.'
             line = line.format(path)
             self._io_manager._display(line)
         else:
             return path
Example #7
0
 def _ljust(string, width):
     start_width = len(stringtools.strip_diacritics(string))
     if start_width < width:
         needed = width - start_width
         suffix = needed * ' '
         result = string + suffix
     else:
         result = string
     return result
Example #8
0
 def _ljust(string, width):
     start_width = len(stringtools.strip_diacritics(string))
     if start_width < width:
         needed = width - start_width
         suffix = needed * ' '
         result = string + suffix
     else:
         result = string
     return result
Example #9
0
 def sort_function(pair):
     string = pair[0]
     if '(' not in string:
         return string
     open_parenthesis_index = string.find('(')
     assert string.endswith(')')
     annotation = string[open_parenthesis_index:]
     annotation = annotation.replace("'", '')
     annotation = stringtools.strip_diacritics(annotation)
     return annotation
Example #10
0
 def sort_function(pair):
     string = pair[0]
     if '(' not in string:
         return string
     open_parenthesis_index = string.find('(')
     assert string.endswith(')')
     annotation = string[open_parenthesis_index:]
     annotation = annotation.replace("'", '')
     annotation = stringtools.strip_diacritics(annotation)
     return annotation
Example #11
0
 def _find_svn_score_name(self):
     from scoremanager import idetools
     manager = self._find_up_to_date_manager(
         repository='svn',
         system=False,
     )
     if manager:
         title = manager._get_title()
         title = stringtools.strip_diacritics(title)
         title = title.lower()
         return title
Example #12
0
 def _find_svn_score_name(self):
     from scoremanager import idetools
     manager = self._find_up_to_date_manager(
         repository='svn',
         system=False,
         )
     if manager:
         title = manager._get_title()
         title = stringtools.strip_diacritics(title)
         title = title.lower()
         return title
Example #13
0
 def search_text(cls, search_string):
     search_string = search_string.lower()
     search_string = stringtools.strip_diacritics(search_string)
     search_string = ','.join(search_string.split())
     query = PostgresEntity.raw("""
         SELECT entity_type,
             entity_id,
             name,
             ts_rank_cd(search_content, query, 63) AS rank
         FROM entities,
             to_tsquery(%s) query
         WHERE query @@ search_content
         ORDER BY rank DESC
         LIMIT 100
         """, search_string)
     return query
Example #14
0
 def search_text(cls, search_string):
     search_string = search_string.lower()
     search_string = stringtools.strip_diacritics(search_string)
     search_string = ','.join(search_string.split())
     query = PostgresEntity.raw("""
         SELECT entity_type,
             entity_id,
             name,
             ts_rank_cd(search_content, query, 63) AS rank
         FROM entities,
             to_tsquery(%s) query
         WHERE query @@ search_content
         ORDER BY rank DESC
         LIMIT 100
         """, search_string)
     return query
Example #15
0
 def _rename_interactively(
     self,
     extension=None,
     file_name_callback=None,
     force_lowercase=True,
     ):
     base_name = os.path.basename(self._path)
     line = 'current name: {}'.format(base_name)
     self._io_manager._display(line)
     getter = self._io_manager._make_getter()
     getter.append_string('new name')
     new_package_name = getter._run()
     if self._session.is_backtracking or new_package_name is None:
         return
     new_package_name = stringtools.strip_diacritics(new_package_name)
     if file_name_callback:
         new_package_name = file_name_callback(new_package_name)
     new_package_name = new_package_name.replace(' ', '_')
     if force_lowercase:
         new_package_name = new_package_name.lower()
     if extension and not new_package_name.endswith(extension):
         new_package_name = new_package_name + extension
     lines = []
     line = 'current name: {}'.format(base_name)
     lines.append(line)
     line = 'new name:     {}'.format(new_package_name)
     lines.append(line)
     self._io_manager._display(lines)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     new_directory = os.path.join(
         os.path.dirname(self._path),
         new_package_name,
         )
     if self._is_svn_versioned():
         # rename package directory
         command = 'svn mv {} {}'
         command = command.format(self._path, new_directory)
         self._io_manager.spawn_subprocess(command)
         # commit
         commit_message = 'renamed {} to {}.'
         commit_message = commit_message.format(
             base_name,
             new_package_name,
             )
         commit_message = commit_message.replace('_', ' ')
         parent_directory = os.path.dirname(self._path)
         command = 'svn commit -m {!r} {}'
         command = command.format(
             commit_message,
             parent_directory,
             )
         self._io_manager.spawn_subprocess(command)
     else:
         command = 'mv {} {}'
         command = command.format(self._path, new_directory)
         self._io_manager.spawn_subprocess(command)
     # update path name to reflect change
     self._path = new_directory
     self._session._is_backtracking_locally = True
Example #16
0
 def string_to_tsvector(cls, string):
     string = string.lower()
     string = stringtools.strip_diacritics(string)
     string = cls._strip_pattern.sub('', string)
     tsvector = peewee.fn.to_tsvector(string)
     return tsvector
Example #17
0
 def _copy_asset(
     self, 
     extension=None,
     new_storehouse=None
     ):
     visible_asset_paths = self._list_visible_asset_paths()
     if not visible_asset_paths:
         messages = ['nothing to copy.']
         messages.append('')
         self._io_manager._display(messages)
         return
     extension = extension or getattr(self, '_extension', '')
     old_path = self._select_visible_asset_path(infinitive_phrase='to copy')
     if not old_path:
         return
     old_name = os.path.basename(old_path)
     if new_storehouse:
         pass
     elif self._session.is_in_score:
         new_storehouse = self._get_current_directory()
     else:
         new_storehouse = self._select_storehouse_path()
         if self._session.is_backtracking or new_storehouse is None:
             return
     message = 'existing {} name> {}'
     message = message.format(self._asset_identifier, old_name)
     self._io_manager._display(message)
     message = 'new {} name'
     message = message.format(self._asset_identifier)
     getter = self._io_manager._make_getter()
     getter.append_string(message)
     help_template = getter.prompts[0].help_template
     string = 'Press <return> to preserve existing name.'
     help_template = help_template + ' ' + string
     getter.prompts[0]._help_template = help_template
     new_name = getter._run()
     new_name = new_name or old_name
     if self._session.is_backtracking or new_name is None:
         return
     new_name = stringtools.strip_diacritics(new_name)
     if hasattr(self, '_file_name_callback'):
         new_name = self._file_name_callback(new_name)
     new_name = new_name.replace(' ', '_')
     if self._force_lowercase:
         new_name = new_name.lower()
     if extension and not new_name.endswith(extension):
         new_name = new_name + extension
     new_path = os.path.join(new_storehouse, new_name)
     if os.path.exists(new_path):
         message = 'already exists: {}'.format(new_path)
         self._io_manager._display(message)
         self._io_manager._acknowledge()
         return
     messages = []
     messages.append('will copy ...')
     messages.append(' FROM: {}'.format(old_path))
     messages.append('   TO: {}'.format(new_path))
     self._io_manager._display(messages)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     if os.path.isfile(old_path):
         shutil.copyfile(old_path, new_path)
     elif os.path.isdir(old_path):
         shutil.copytree(old_path, new_path)
     else:
         raise TypeError(old_path)
     if os.path.isdir(new_path):
         for directory_entry in os.listdir(new_path):
             if not directory_entry.endswith('.py'):
                 continue
             path = os.path.join(new_path, directory_entry)
             self._replace_in_file(
                 path,
                 old_name,
                 new_name,
                 )
Example #18
0
 def sort_function(pair):
     string = pair[0]
     string = stringtools.strip_diacritics(string)
     string = string.replace("'", '')
     return string
Example #19
0
    def _change_input_to_directive(self, input_):
        r'''Match order:
        
            1. all command sections
            2. 'assets' section, if it exists
            3. 'material summary', if it exists

        This avoids file name new-stylesheet.ily aliasing the (new) command.
        '''
        input_ = stringtools.strip_diacritics(input_)
        if input_ == '!':
            return
        if input_.startswith('!'):
            if self._has_shell_command():
                return input_
            else:
                return
        ends_with_bang = input_.endswith('!')
        input_ = input_.strip('!')
        if input_.endswith('/'):
            is_autoadvancing = self._session.is_autoadvancing
            if is_autoadvancing:
                self._session._autoadvance_depth = 0
            else:
                self._session._autoadvance_depth = 1
            input_ = input_.strip('/')
        if input_.endswith('@'):
            self._session._is_autostarting = True
            self._session._is_autoadvancing = True
            input_ = input_.strip('@')
        if self._user_enters_nothing(input_):
            default_value = None
            for section in self.menu_sections:
                if section._has_default_value:
                    default_value = section._default_value
            if default_value is not None:
                return self._enclose_in_list(default_value)
        elif input_ in ('hh', 'ss', 'q', 'b', '<return>'):
            self._session._pending_redraw = True
            return input_
        elif input_ == '??' and self._has_help_command():
            self._session._pending_redraw = True
            return input_
        elif input_ == 's' and self._session.is_in_score:
            self._session._pending_redraw = True
            return input_
        # match on exact case
        asset_section, material_summary_section = None, None
        for section in self.menu_sections:
            if section.is_information_section:
                continue
            if section.is_asset_section:
                asset_section = section
                continue
            if section.is_material_summary_section:
                material_summary_section = section
                continue
            for menu_entry in section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if asset_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        elif material_summary_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        # lower case version of the two sections above
        asset_section = None
        for section in self.menu_sections:
            if section.is_information_section:
                continue
            elif section.is_asset_section:
                asset_section = section
                continue
            elif section.is_material_summary_section:
                material_summary_section = section
                continue
            for menu_entry in section:
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if asset_section is not None:
            for menu_entry in asset_section:
                #if menu_entry.matches(input_):
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        elif material_summary_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if self._user_enters_argument_range(input_):
            return self._handle_argument_range_input(input_)
Example #20
0
 def string_to_tsvector(cls, string):
     string = string.lower()
     string = stringtools.strip_diacritics(string)
     string = cls._strip_pattern.sub('', string)
     tsvector = peewee.fn.to_tsvector(string)
     return tsvector
Example #21
0
 def sort_function(pair):
     string = pair[0]
     string = stringtools.strip_diacritics(string)
     string = string.replace("'", '')
     return string
Example #22
0
 def _rename_interactively(
     self,
     extension=None,
     file_name_callback=None,
     force_lowercase=True,
 ):
     base_name = os.path.basename(self._path)
     line = 'current name: {}'.format(base_name)
     self._io_manager._display(line)
     getter = self._io_manager._make_getter()
     getter.append_string('new name')
     new_package_name = getter._run()
     if self._session.is_backtracking or new_package_name is None:
         return
     new_package_name = stringtools.strip_diacritics(new_package_name)
     if file_name_callback:
         new_package_name = file_name_callback(new_package_name)
     new_package_name = new_package_name.replace(' ', '_')
     if force_lowercase:
         new_package_name = new_package_name.lower()
     if extension and not new_package_name.endswith(extension):
         new_package_name = new_package_name + extension
     lines = []
     line = 'current name: {}'.format(base_name)
     lines.append(line)
     line = 'new name:     {}'.format(new_package_name)
     lines.append(line)
     self._io_manager._display(lines)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     new_directory = os.path.join(
         os.path.dirname(self._path),
         new_package_name,
     )
     if self._is_svn_versioned():
         # rename package directory
         command = 'svn mv {} {}'
         command = command.format(self._path, new_directory)
         self._io_manager.spawn_subprocess(command)
         # commit
         commit_message = 'renamed {} to {}.'
         commit_message = commit_message.format(
             base_name,
             new_package_name,
         )
         commit_message = commit_message.replace('_', ' ')
         parent_directory = os.path.dirname(self._path)
         command = 'svn commit -m {!r} {}'
         command = command.format(
             commit_message,
             parent_directory,
         )
         self._io_manager.spawn_subprocess(command)
     else:
         command = 'mv {} {}'
         command = command.format(self._path, new_directory)
         self._io_manager.spawn_subprocess(command)
     # update path name to reflect change
     self._path = new_directory
     self._session._is_backtracking_locally = True
Example #23
0
 def _copy_asset(self, extension=None, new_storehouse=None):
     visible_asset_paths = self._list_visible_asset_paths()
     if not visible_asset_paths:
         messages = ['nothing to copy.']
         messages.append('')
         self._io_manager._display(messages)
         return
     extension = extension or getattr(self, '_extension', '')
     old_path = self._select_visible_asset_path(infinitive_phrase='to copy')
     if not old_path:
         return
     old_name = os.path.basename(old_path)
     if new_storehouse:
         pass
     elif self._session.is_in_score:
         new_storehouse = self._get_current_directory()
     else:
         new_storehouse = self._select_storehouse_path()
         if self._session.is_backtracking or new_storehouse is None:
             return
     message = 'existing {} name> {}'
     message = message.format(self._asset_identifier, old_name)
     self._io_manager._display(message)
     message = 'new {} name'
     message = message.format(self._asset_identifier)
     getter = self._io_manager._make_getter()
     getter.append_string(message)
     help_template = getter.prompts[0].help_template
     string = 'Press <return> to preserve existing name.'
     help_template = help_template + ' ' + string
     getter.prompts[0]._help_template = help_template
     new_name = getter._run()
     new_name = new_name or old_name
     if self._session.is_backtracking or new_name is None:
         return
     new_name = stringtools.strip_diacritics(new_name)
     if hasattr(self, '_file_name_callback'):
         new_name = self._file_name_callback(new_name)
     new_name = new_name.replace(' ', '_')
     if self._force_lowercase:
         new_name = new_name.lower()
     if extension and not new_name.endswith(extension):
         new_name = new_name + extension
     new_path = os.path.join(new_storehouse, new_name)
     if os.path.exists(new_path):
         message = 'already exists: {}'.format(new_path)
         self._io_manager._display(message)
         self._io_manager._acknowledge()
         return
     messages = []
     messages.append('will copy ...')
     messages.append(' FROM: {}'.format(old_path))
     messages.append('   TO: {}'.format(new_path))
     self._io_manager._display(messages)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     if os.path.isfile(old_path):
         shutil.copyfile(old_path, new_path)
     elif os.path.isdir(old_path):
         shutil.copytree(old_path, new_path)
     else:
         raise TypeError(old_path)
     if os.path.isdir(new_path):
         for directory_entry in os.listdir(new_path):
             if not directory_entry.endswith('.py'):
                 continue
             path = os.path.join(new_path, directory_entry)
             self._replace_in_file(
                 path,
                 old_name,
                 new_name,
             )
Example #24
0
    def _change_input_to_directive(self, input_):
        r'''Match order:
        
            1. all command sections
            2. 'assets' section, if it exists
            3. 'material summary', if it exists

        This avoids file name new-stylesheet.ily aliasing the (new) command.
        '''
        input_ = stringtools.strip_diacritics(input_)
        if input_ == '!':
            return
        if input_.startswith('!'):
            if self._has_shell_command():
                return input_
            else:
                return
        ends_with_bang = input_.endswith('!')
        input_ = input_.strip('!')
        if input_.endswith('/'):
            is_autoadvancing = self._session.is_autoadvancing
            if is_autoadvancing:
                self._session._autoadvance_depth = 0
            else:   
                self._session._autoadvance_depth = 1
            input_ = input_.strip('/')
        if input_.endswith('@'):
            self._session._is_autostarting = True
            self._session._is_autoadvancing = True
            input_ = input_.strip('@')
        if self._user_enters_nothing(input_):
            default_value = None
            for section in self.menu_sections:
                if section._has_default_value:
                    default_value = section._default_value
            if default_value is not None:
                return self._enclose_in_list(default_value)
        elif input_ in ('hh', 'ss', 'q', 'b', '<return>'):
            self._session._pending_redraw = True
            return input_
        elif input_ == '??' and self._has_help_command():
            self._session._pending_redraw = True
            return input_
        elif input_ == 's' and self._session.is_in_score:
            self._session._pending_redraw = True
            return input_
        # match on exact case
        asset_section, material_summary_section = None, None
        for section in self.menu_sections:
            if section.is_information_section:
                continue
            if section.is_asset_section:
                asset_section = section
                continue
            if section.is_material_summary_section:
                material_summary_section = section
                continue
            for menu_entry in section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if asset_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        elif material_summary_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        # lower case version of the two sections above
        asset_section = None
        for section in self.menu_sections:
            if section.is_information_section:
                continue
            elif section.is_asset_section:
                asset_section = section
                continue
            elif section.is_material_summary_section:
                material_summary_section = section
                continue
            for menu_entry in section:
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if asset_section is not None:
            for menu_entry in asset_section:
                #if menu_entry.matches(input_):
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        elif material_summary_section is not None:
            for menu_entry in asset_section:
                if menu_entry.matches(input_.lower()):
                    return_value = menu_entry.return_value
                    if ends_with_bang:
                        return_value = return_value + '!'
                    return self._enclose_in_list(return_value)
        if self._user_enters_argument_range(input_):
            return self._handle_argument_range_input(input_)