dhunter/core/file_hash.py
def calculate_hash(self) -> None:
        """Calculates hash for given file of this FileHash object.

        :raises FileNotFoundError
        :raises OSError
        """
        if self.name is None:
            raise OSError('File name cannot be None')
        elif self.path is None:
            raise OSError('File path cannot be None')

        if not os.path.exists(self.path):
            raise FileNotFoundError('"{name}" not found'.format(name=self.path))
        elif not os.path.isfile(self.path):
            raise OSError('"{name}" is not a file'.format(name=self.path))

        dir_name = os.path.dirname(self.path)
        cmd = []
        # if self.size > (1024 * 1024 * 10):
        #     cmd = ['nice', '-n', str(5)]
        cmd.extend(['md5sum', '-b', '--', self.name])
        rc, elapsed_time_seconds, stdout, stderr = Util.execute(cmd, dir_name)

        from .log import Log
        if rc == 0:
            # hash is always plain hex string. No need for utf-8 here, esp. it ends up in JSON files.
            self.hash = stdout[0].decode('utf8').split(' ')[0]
            self.hash_time_seconds = elapsed_time_seconds

            Log.d('{name}: hash {hash} in {sec} secs.'.format(name=self.path, hash=self.hash,
                                                              sec=self.hash_time_seconds))
        else:
            Log.e('Failed to hash "{name}"'.format(name=self.path))
Calculates hash for given file of this FileHash object.

        :raises FileNotFoundError
        :raises OSError
        
Calculates hash for given file of this FileHash object.
Calculates hash for given file of this FileHash object .
def calculate_hash(self) -> None:
        if self.name is None:
            raise OSError('File name cannot be None')
        elif self.path is None:
            raise OSError('File path cannot be None')
        if not os.path.exists(self.path):
            raise FileNotFoundError('"{name}" not found'.format(name=self.path))
        elif not os.path.isfile(self.path):
            raise OSError('"{name}" is not a file'.format(name=self.path))
        dir_name = os.path.dirname(self.path)
        cmd = []
        cmd.extend(['md5sum', '-b', '--', self.name])
        rc, elapsed_time_seconds, stdout, stderr = Util.execute(cmd, dir_name)
        from .log import Log
        if rc == 0:
            self.hash = stdout[0].decode('utf8').split(' ')[0]
            self.hash_time_seconds = elapsed_time_seconds
            Log.d('{name}: hash {hash} in {sec} secs.'.format(name=self.path, hash=self.hash,
                                                              sec=self.hash_time_seconds))
        else:
            Log.e('Failed to hash "{name}"'.format(name=self.path))
def calculate_hash ( self ) -> None : if self . name is None : raise OSError ( 'File name cannot be None' ) elif self . path is None : raise OSError ( 'File path cannot be None' ) if not os . path . exists ( self . path ) : raise FileNotFoundError ( '"{name}" not found' . format ( name = self . path ) ) elif not os . path . isfile ( self . path ) : raise OSError ( '"{name}" is not a file' . format ( name = self . path ) ) dir_name = os . path . dirname ( self . path ) cmd = [ ] cmd . extend ( [ 'md5sum' , '-b' , '--' , self . name ] ) rc , elapsed_time_seconds , stdout , stderr = Util . execute ( cmd , dir_name ) from . log import Log if rc == 0 : self . hash = stdout [ 0 ] . decode ( 'utf8' ) . split ( ' ' ) [ 0 ] self . hash_time_seconds = elapsed_time_seconds Log . d ( '{name}: hash {hash} in {sec} secs.' . format ( name = self . path , hash = self . hash , sec = self . hash_time_seconds ) ) else : Log . e ( 'Failed to hash "{name}"' . format ( name = self . path ) )
Calculates hash for given file of this FileHash object.
Calculates hash for given file of this FileHash object .
"""Calculates hash for given file of this FileHash object.

        :raises FileNotFoundError
        :raises OSError
        """ # if self.size > (1024 * 1024 * 10): #     cmd = ['nice', '-n', str(5)] # hash is always plain hex string. No need for utf-8 here, esp. it ends up in JSON files.
self