Exemple #1
0
def _iterate():

    r = c['sourcedir']
    t = ut.join_path(c['tempdir'], 'encoding.dat')
    w = h.read('walk.txt')
    for file_ in w:
        path = ut.join_path(r, file_)
        s = ut.read_strings(path)
        ut.write_strings(s, t)
Exemple #2
0
def _iterate():

    r = c['sourcedir']
    t = ut.join_path(c['tempdir'], 'encoding.dat')
    w = h.read('walk.txt')
    for file_ in w:
        path = ut.join_path(r, file_)
        s = ut.read_strings(path)
        ut.write_strings(s, t)
Exemple #3
0
    def vp2a(self, patchname, archpath, params):
        """ Display patch and archive diff sections that use its files
        
        Args:
            patchname (string): name of patch file
            archpath  (string): path to archive file
            params    (dict):   parameters
                patchdir (string, required): path of patches folder
                tempdir  (string, required): path to store temporary data
                
        Raises:    
            PT_ParameterError for any missing files
        
        Notes:
            Launches the editor synchronously, since a temporary file is created to hold
            the archive sections.
        """
        #--

        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')

        sourcedir = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        tempdir = self._check_directory_param(params, 'tempdir')

        patchpath = self._check_filename_param(patchdir, patchname,
                                               'patchname')
        if (not ut.is_file(archpath)):
            raise PT_NotFoundError(self.name, archpath)

        # Get list of files used by the patch
        filelist = Patch.list_files(patchpath)
        filepaths = [ut.join_path(sourcedir, file_) for file_ in filelist]

        # Get archive diff sections that use any of the files
        strings = []
        for diff in self._get_diffs(archpath, filepaths):
            strings += diff

        if (len(strings) == 0):
            return []

        # Store the diff sections in a temporary file
        archname = archpath[archpath.rfind('/') + 1:]
        tempname = archname + '.tmp'
        temppath = ut.join_path(tempdir, tempname)
        ut.write_strings(strings, temppath)

        self._view([patchpath, temppath], True)

        # Note that we requested _view to wait for subprocess exit above,
        # so that we do not try to delete the file while it is in use.

        os.remove(temppath)
Exemple #4
0
    def vp2a(self, patchname, archpath, params):
        """ Display patch and archive diff sections that use its files
        
        Args:
            patchname (string): name of patch file
            archpath  (string): path to archive file
            params    (dict):   parameters
                patchdir (string, required): path of patches folder
                tempdir  (string, required): path to store temporary data
                
        Raises:    
            PT_ParameterError for any missing files
        
        Notes:
            Launches the editor synchronously, since a temporary file is created to hold
            the archive sections.
        """
        #--
        
        if (not isinstance(params, dict)):
            raise PT_ParameterError(self.name, 'params')
        
        sourcedir  = self._check_directory_param(params, 'sourcedir')
        patchdir = self._check_directory_param(params, 'patchdir')
        tempdir = self._check_directory_param(params, 'tempdir')
        
        patchpath = self._check_filename_param(patchdir, patchname, 'patchname')
        if (not ut.is_file(archpath)):
            raise PT_NotFoundError(self.name, archpath)
        
        # Get list of files used by the patch
        filelist = Patch.list_files(patchpath)
        filepaths = [ut.join_path(sourcedir, file_) for file_ in filelist]

        # Get archive diff sections that use any of the files
        strings = []
        for diff in self._get_diffs(archpath, filepaths):
            strings += diff
        
        if (len(strings) == 0):
            return []
        
        # Store the diff sections in a temporary file
        archname = archpath[archpath.rfind('/') + 1:]
        tempname = archname + '.tmp'
        temppath = ut.join_path(tempdir, tempname)
        ut.write_strings(strings, temppath)
        
        self._view([patchpath, temppath], True)
        
        # Note that we requested _view to wait for subprocess exit above,
        # so that we do not try to delete the file while it is in use.
        
        os.remove(temppath)
Exemple #5
0
def convert_api_data(config):

    srcroot = config['srcroot']
    sources = config['sources']
    data = []
    for source in sources:
        print('extract: ' + source)
        path = ut.join_path(srcroot, source)
        strings  = Strings(ut.read_strings(path))
        sections = strings.extract('#++','#--')
        if (len(sections) > 0):
            sections = [conv_section(section) for section in sections]
            data += Strings.join(sections)
        else:
            pass
    
    ut.write_strings(data, './_rest/api.txt')
Exemple #6
0
 def write(self, data, filepath):
     """ Write data to path as a sequence of '\\n' terminated lines.
         
         Args:
             data (various): any variable
             filepath (string): file path
         
         Notes:
             All data items are "pretty printed", i.e. they are split into lines
             according to content.
     """
     if (isinstance(data, list)):
         ut.write_strings(data, filepath)
     elif (isinstance(data, dict)):
         ut.write_strings(self._format_dict(data))
     elif (ut.is_string_type(data)):
         ut.write_file(data + '\n', filepath)
     else:
         raise ParametersError('text')
Exemple #7
0
 def write(self, data, filepath):
     """ Write data to path as a sequence of '\\n' terminated lines.
         
         Args:
             data (various): any variable
             filepath (string): file path
         
         Notes:
             All data items are "pretty printed", i.e. they are split into lines
             according to content.
     """
     if (isinstance(data, list)):
         ut.write_strings(data, filepath)
     elif (isinstance(data, dict)):
         ut.write_strings(self._format_dict(data))
     elif (ut.is_string_type(data)):
         ut.write_file(data + '\n', filepath)
     else:
         raise ParametersError('text')
Exemple #8
0
 def watch(self, archpath):
     """ View files related to archive diff sections
     
     Args:
         archpath (string): path to patch archive file
         
     Returns:
         None. Output is a series of launches of the Viewer to view the files.
         
     Raises:
         PT_ParameterError
         PT_NotFoundError
     """
     #--
     
     if (not ut.is_string_type(archpath)):
         raise PT_ParameterError(self.name, 'archpath') 
     
     if (not ut.is_file(archpath)):
         raise PT_NotFoundError(self.name, archpath)
            
     tempfile = ut.join_path(self._tempdir, 'archdata.txt')
     filedata = self._patchset.get_file_data()
     filenames = [key for key in filedata]
     a = Archive(archpath)
     s = a.sections(filenames)
     print("Found %d matching sections" % len(s))
     v = Viewer()
     for section in s:
         ut.write_strings(section, tempfile)
         filename = ut.get_string_filename(section[1])
         filepath = ut.join_path(self._sourcedir, filename)
         patchfiles = []
         for (fn, _) in filedata[filename]:
             patchfiles += [ut.join_path(self._patchdir, fn)]
         r = v.view([tempfile, filepath] + patchfiles)
         print(r)