LinuxCommandLibrary

gyb

Backup and restore Gmail or Google Workspace

TLDR

Estimate the number and the size of all emails on your Gmail account

$ gyb --email [email@gmail.com] --action estimate
copy

Backup a Gmail account to a specific directory
$ gyb --email [email@gmail.com] --action backup --local-folder [path/to/directory]
copy

Backup only important or starred emails from a Gmail account to the default local folder
$ gyb --email [email@gmail.com] --search "[is:important OR is:starred]"
copy

Restore from a local folder to a Gmail account
$ gyb --email [email@gmail.com] --action restore --local-folder [path/to/directory]
copy

SYNOPSIS

gyb [options] inputfile

PARAMETERS

--line-directive=
    Format for line directives (default: '#line %(line)d "%(filename)s"').

--output=
    Write the output to the specified file.

-D =
    Define a variable with a value for use in the template.

--header=
    Prepend the contents of this file to the output.

--footer=
    Append the contents of this file to the output.

--no-docstring-stripping
    Do not strip docstrings from the generated code.

--check-output
    Check that the output matches the expected output.

--verbose
    Output detailed information about the process.

--help
    Show the help message and exit.

DESCRIPTION

gyb (Generate Your Boilerplate) is a Python preprocessor used to generate repetitive code. It allows you to write a template containing regular code interspersed with Python code snippets, which when executed, generates the final code. This is especially useful for avoiding manual copy-pasting and maintaining consistency across different parts of a project. gyb files typically end in '.gyb' and the output is often saved with a different extension reflecting the target language (e.g., '.swift' or '.c'). It is frequently utilized within larger projects to automatically create different variations of a particular structure, for example data structures that may use different types as generic parameters.

It provides a mechanism to handle redundant code by automating its generation. It's particularly helpful when targeting multiple architectures, data types, or code variations from a single source of truth. By using GYB it makes the source code shorter and easier to understand, while still offering the performance benefits of generating code that is specific to each case. It can be used to automate the generation of the source code files themselves, and also header files, and other related code.

CAVEATS

gyb relies on correct Python syntax within the templates, so Python errors can occur during processing. Debugging the interaction between the template and the code being generated can be tricky. The quality of the generated code is completely dependent on the quality of the gyb template. Complex logic in templates may become difficult to manage and maintain.

TEMPLATE SYNTAX

gyb templates contain a mixture of regular text and Python code snippets.

Python code is embedded within special delimiters. `<% ... %>` executes the Python code, while `<%= ... %>` executes the Python code and inserts the result into the output. The Python code can include variable definitions, loops, conditional statements, and function calls, allowing for dynamic code generation.

Comments in a GYB file will be removed from the generated output.

EXAMPLE

Input (example.gyb):

<% for i in range(3): %>
Value: <%= i %>
<% end %>

Command:

gyb example.gyb

Output:

Value: 0
Value: 1
Value: 2

HISTORY

gyb was created to address the challenge of generating repetitive code in projects where manual duplication would be error-prone and difficult to maintain.

Its development was driven by needs to generate source code for different data types in a generic manner. One prominent use of gyb is in the Swift project, where it is used extensively to generate code for different numeric types, container structures, and more. This reduces the maintenance burden and increases the consistency of the codebase. The tool has evolved from the need for automated code generation, particularly in environments where manual coding is not sufficient to tackle the repetition within projects.

SEE ALSO

m4(1), sed(1), awk(1)

Copied to clipboard