Weekly #15

@Date : 2019-12-15 19:41:33

@Author : Lewis Tian (taseikyo@gmail.com)

@Link : github.com/taseikyo

@Range : 2019-12-15 - 2019-12-21

Weekly #15 Photo by Krystian Tambur on Unsplash

Table of Contents

review

This article introduces what the apf (KVM async page fault) is and how kvm does the apf work.

As the title indicates, this article introduces us to IOMMU.

tip

Gmail Filter

Gmail label is very useful when used with filter.

Suppose your gmail is abc@gmail.com, then create a new label "note".

Next, create a new filter and put "abc+note@gmail.com" into the "To" field.

You can then send the email to abc+note@gmail.com, and gmail will mark the email as "notes".

Function argument unpacking


def func(x, y, z):
    print(x, y, z)

tuple_vec = (1, 0, 1)
dict_vec = {'x': 1, 'y': 0, 'z': 1}

>>> func(*tuple_vec)
1, 0, 1

>>> func(**dict_vec)
1, 0, 1

Deal with a file path

pathlib is more elegent than os/os.path

from pathlib import Path

>>> Path.cwd()
WindowsPath('F:/Codes/Python')

>>> Path.home()
WindowsPath('C:/Users/tian')
  • Creating Paths
# join the parts of the path using operator `/`
>>> Path.home() / 'python' / 'scripts' / 'test.py'
WindowsPath('C:/Users/tian/python/scripts/test.py')

# If you do not like `/`, `.joinpath()` also works
Path.home().joinpath('python', 'scripts', 'test.py')
WindowsPath('C:/Users/tian/python/scripts/test.py')
  • Reading and Writing Files
path = Path.cwd() / 'test.py'

# use `open()`
with open(path, mode='r') as fid:
    headers = [line.strip() for line in fid if line.startswith('#')]
print('\n'.join(headers))

# call `.open()` on the Path object
with path.open(mode='r') as fid:
    https://github.com/taseikyo/arts/blob/master.

# `.read_text()` `.read_bytes()`
>>> path.read_text(encoding='utf-8')
<the contents of the test.py-file>

# `.write_text()` `.write_bytes()`
>>> path = Path.cwd() / 'write_test.py'
>>> path.write_text('write test.\n', encoding='utf-8')
12
>>> path.read_text(encoding='utf-8')
'write test.\n'

# `.resolve()` return the full path
>>> path = Path.cwd() / 'test.py'
>>> path.resolve()
WindowsPath('F:/Codes/Python/write_test.py')
>>> path.resolve().parent
WindowsPath('F:/Codes/Python')
  • Picking Out Components of a Path
    • .name: the file name without any directory
    • .parent: the directory containing the file, or the parent directory if path is a directory
    • .stem: the file name without the suffix
    • .suffix: the file extension
    • .anchor: the part of the path before the directories

I think this is the most useful part

>>> path
WindowsPath('F:/Codes/Python/write_test.py')
>>> path.name
'write_test.py'
>>> path.stem
'write_test'
>>> path.suffix
'.py'
>>> path.parent
WindowsPath('F:/Codes/Python')
>>> path.parent.parent
WindowsPath('F:/Codes')
>>> path.anchor
'F:\\'

Note that .parent returns a new Path object, whereas the other properties return strings. This means for instance that .parent can be chained as in the last example or even combined with / to create completely new paths:

>>> path.parent.parent / ('new' + path.suffix)
WindowsPath('F:/Codes/new.py')
  • Moving and Deleting Files
# To move a file, use .replace().
>>> path
WindowsPath('F:/Codes/Python/write_test.py')
>>> path.with_suffix('.md')
WindowsPath('F:/Codes/Python/write_test.md')
# rename write_test.py to write_test.md
>>> path.replace(path.with_suffix('.md'))
# rename write_test.py to read_test.py
>>> path.replace(path.with_name('read_test.py'))

# `.rmdir()` delete directory
>>> path = Path.cwd() / 'tmp'
>>> path.rmdir()

# `.unlink()` delete file
>>> path = Path.cwd() / 'tmp.txt'
>>> path.unlink()
  • List subdirs
>>> path = Path.cwd()
>>> list(path/iterdir())
[WindowsPath('F:/Codes/Python/calculator.py'),
 WindowsPath('F:/Codes/Python/Crawler'),
 WindowsPath('F:/Codes/Python/Utils')
 https://github.com/taseikyo/arts/blob/master.]
  • Filter subdirs
>>> list(Path.cwd().glob('*.p*'))
[WindowsPath('F:/Codes/Python/calculator.py'),
 WindowsPath('F:/Codes/Python/no_name.py'),
 WindowsPath('F:/Codes/Python/read_test.py'),
 WindowsPath('F:/Codes/Python/win32MsgBox.py')]
# `.rglob()` (recursive glob)
>>> list(Path.cwd().rglob('*.p*'))
[WindowsPath('F:/Codes/Python/calculator.py'),
 WindowsPath('F:/Codes/Python/Crawler/hust/person/index.py')
 https://github.com/taseikyo/arts/blob/master.]

Merge video and audio into a new video

The motivation is that I downloaded mp4 and m4a files from YouTube (the chrome extension divided the original video into mp4 and m4a). I want to merge them and add the feature to my FFmpeg Helper.

I got this method when I used MarukoToolbox to compress a video and maintain the original audio quality.

The MarukoToolbox compression process is to extract audio first, then compress video, and finally merge them.

The following command is the last step:

mp4box.exe -add "base_media.mp4#trackID=1:name=" -add "base_media.m4a#trackID=1:name=" -new "new_video.mp4"

share

The four posts introduce us the workflow of KVM including the basic of kvm, how to create and run a vm, how kvm implements cpu virtualization and memory virtualization.

It is a bit difficult to fully understand, because some description is not very detailed (or I am too stupid! ;3).

The recommended books are worth reading:

  1. Operating System textbook
  2. Linux kernel architecture or Understanding the LINUX kernel
  3. System Virtualization: Theory & Implementation - Intel

I have read parts of Understanding the LINUX kernel (3th ed). Compared with Linux system programming, U.L.K. is more worth reading.

This post provides a detail introduction to the Linux boot and startup processes.

In general, there are two steps to boot a Linux computer and make it usable: boot and startup.

  • The boot sequence starts when the computer is turned on, and is completed when the kernel is initialized and systemd is launched.
    • POST
    • GRUB2
      • stage 1
      • stage 1.5
      • stage 2
      • kernel
  • The startup process then takes over and finishes the task of getting the Linux computer into an operational state.
    • systemd

results matching ""

    No results matching ""