Ejemplo n.º 1
0
 def sdict(self):
     path_info = PathInfo(self.node, self.name)
     if not path_info.exists:
         return None
     else:
         return {
             'target': path_info.symlink_target if path_info.is_symlink else "",
             'type': 'symlink' if path_info.is_symlink else path_info.stat['type'],
             'owner': path_info.owner,
             'group': path_info.group,
         }
Ejemplo n.º 2
0
 def sdict(self):
     path_info = PathInfo(self.node, self.name)
     if not path_info.exists:
         return None
     else:
         return {
             'target': path_info.symlink_target if path_info.path_type == 'symlink' else "",
             'type': path_info.path_type,
             'owner': path_info.owner,
             'group': path_info.group,
         }
Ejemplo n.º 3
0
 def display_on_delete(self, sdict):
     del sdict['content_hash']
     path_info = PathInfo(self.node, self.name)
     if (sdict['size'] < DIFF_MAX_FILE_SIZE and path_info.is_text_file):
         sdict['content'] = diff_value_text(
             "",
             get_remote_file_contents(self.node, self.name),
             "",
         ).rstrip("\n")
     if path_info.is_file:
         sdict['size'] = f"{sdict['size']} bytes"
     return sdict
Ejemplo n.º 4
0
    def sdict(self):
        """This is how the world is right now"""
        path_info = PathInfo(self.node, self.name)
        if not path_info.exists:
            return None
        else:
            sdict = {
                'type': 'download',
                'sha256': self.__hash_remote_file(self.name)
            }

        return sdict
Ejemplo n.º 5
0
 def sdict(self):
     path_info = PathInfo(self.node, self.name)
     if not path_info.exists:
         return None
     else:
         return {
             'type':
             'file' if path_info.is_file else path_info.stat['type'],
             'content_hash': path_info.sha1 if path_info.is_file else None,
             'mode': path_info.mode,
             'owner': path_info.owner,
             'group': path_info.group,
             'size': path_info.size,
         }
Ejemplo n.º 6
0
 def sdict(self):
     path_info = PathInfo(self.node, self.name)
     if not path_info.exists:
         return None
     else:
         paths_to_purge = []
         if self.attributes['purge']:
             paths_to_purge = list(self._get_paths_to_purge())
         return {
             'type': path_info.path_type,
             'mode': path_info.mode,
             'owner': path_info.owner,
             'group': path_info.group,
             'paths_to_purge': paths_to_purge,
         }
Ejemplo n.º 7
0
 def display_dicts(self, cdict, sdict, keys):
     if ('content_hash' in keys
             and self.attributes['content_type'] not in ('base64', 'binary')
             and sdict['size'] < DIFF_MAX_FILE_SIZE
             and len(self.content) < DIFF_MAX_FILE_SIZE
             and PathInfo(self.node, self.name).is_text_file):
         keys.remove('content_hash')
         keys.append('content')
         del cdict['content_hash']
         del sdict['content_hash']
         cdict['content'] = self.content
         sdict['content'] = get_remote_file_contents(self.node, self.name)
     if 'type' in keys:
         with suppress(ValueError):
             keys.remove('content_hash')
     return (cdict, sdict, keys)
Ejemplo n.º 8
0
    def __hash_remote_file(self, filename):
        path_info = PathInfo(self.node, filename)
        if not path_info.is_file:
            return None

        if hasattr(path_info, 'sha256'):
            return path_info.sha256
        else:
            """"pending pr so do it manualy"""
            if self.node.os == 'macos':
                result = self.node.run("shasum -a 256 -- {}".format(quote(filename)))
            elif self.node.os in self.node.OS_FAMILY_BSD:
                result = self.node.run("sha256 -q -- {}".format(quote(filename)))
            else:
                result = self.node.run("sha256sum -- {}".format(quote(filename)))
            return force_text(result.stdout).strip().split()[0]