Nazar-Pichak / One_Way_Folder_Sync

Testing task as a reply from Veeam Software IT Company located in Czech Republic
https://www.veeam.com/
MIT License
0 stars 0 forks source link

One Way Folder Synchronization Script

Python Last Commit Forks Stars Issues Contributors License: MIT Greetings Workflow

Overview πŸ‘ πŸ‘

The code in the main.py is a Python script designed to synchronize the contents of a source directory with a destination directory. The script offers command-line arguments for flexibility, allowing users to specify paths for source and destination directories, define a log file location, and set a synchronization period.

Key Features:

Modules Used:

Explanation and complexity as a base of project πŸ€”

When file explorers count the memory size of hidden files and folders, they typically follow a set of steps that involve file system interactions and specific rules about what constitutes a "hidden" file. Here’s a detailed explanation of how this process generally works:

1. File System Interactions

File explorers interact with the file system to gather information about files and directories. The file system keeps track of various attributes of each file, including:

2. Identifying Hidden Files

Hidden files are usually identified based on certain attributes. The criteria for what constitutes a hidden file can vary between operating systems:

3. Traversing Directories

When counting the size of files in a directory, file explorers typically do the following:

4. Calculating Size

For each file or folder that the explorer encounters, it will perform the following steps:

5. Displaying Results

After traversing the entire directory structure and calculating the sizes, the explorer will typically display the total size of the selected directory and its contents, which can include both visible and hidden files, depending on user settings. If the user has opted to show hidden files, those sizes will be included in the total. If not, they will be omitted.

Useful researches πŸ”Ž

File explorers often do not include hidden files and folders in their calculations of memory size for a few key reasons related to user experience, system performance, and the nature of hidden files themselves. Based on this we can make a conclusion that we can't see visually a whole memory size of the some folders in the file explorers (Windows, Linux, MacOS) even when we copy them. The original and copy looks the same, but in case copying via programming code operations we can run into a strange difference in memory size of original and a copy of the same folder.

Installation and usage guide βš™

First ensure you have installed Python and pip on your system.

1. Upgrade your pip

python -m pip install --upgrade pip

2. Clone repo

git clone https://github.com/Nazar-Pichak/One_Way_Folder_Sync.git

3. Navigate into your git repo

cd >> cloned repo

4. Create virtual environment

python -m venv env

5. Activate virtual environment

python -m pip install -r requirements.txt

7. Run the code


**8. Results**

<picture>
  <source srcset="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.webp" type="image/webp">
  <img src="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.gif" alt="πŸš€" width="38" height="38">
</picture>
<picture>
  <source srcset="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.webp" type="image/webp">
  <img src="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.gif" alt="πŸš€" width="38" height="38">
</picture>
<picture>
  <source srcset="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.webp" type="image/webp">
  <img src="https://fonts.gstatic.com/s/e/notoemoji/latest/1f680/512.gif" alt="πŸš€" width="38" height="38">
</picture>

So now, when our **rocket** is running, it will create an identical copy of the `source directory` into previous desired place. As this is one way synchronization, we have to assume that `source directory` is a **main** directory.
To see general functionality, make any changes to the `source directory` by creating, deleting, updating files and folders while script is running with infinit loop and follow changes into `destination directory`. We have to see that both directories are the same. However when you try to change content of the `destination directory`, it will be overwritten corresponding to the content of the `source directory`.    

## Contribution guide <picture> <source srcset="https://fonts.gstatic.com/s/e/notoemoji/latest/270f_fe0f/512.webp" type="image/webp"> <img src="https://fonts.gstatic.com/s/e/notoemoji/latest/270f_fe0f/512.gif" alt="✏" width="32" height="32"> </picture>

Contributions and improvements are wellcome as well. Please feel free to report any [issues](https://github.com/Nazar-Pichak/One_Way_Folder_Sync/issues) and bugs as this project is completely new. Improvments are still being made.
You can also take this script as a basis for implementing **two way folder synchronization** for example, and create a new branch with more complex functionality.     

**1. Make your king Fork πŸ‘‡πŸ‘‡πŸ‘‡**
- This will create a copy of the repository in your GitHub account

![alt text](images/img_2.png)

**2. Clone Forked repository localy πŸ‘‡πŸ‘‡πŸ‘‡**

git clone https://github.com/your_name/One_Way_Folder_Sync.git

**3. Set Up the Upstream Remote**

- Navigate into the project:

cd >> cloned repo

- Add the original repository as an upstream remote to keep your fork in sync:

git remote add upstream https://github.com/Nazar-Pichak/One_Way_Folder_Sync.git

This allows you to keep your forked repository up-to-date with the latest changes from the main repository.

- Verify remotes with:

git remote -v

**4. Setting up the local environment**

python -m venv env

**5. Activate virtual environment**

- For Windows:

.venv\Scripts\activate

- For Unix/macOS:

source .venv/bin/activate

**6. Install dependencies into virtual environment**

python -m pip install -r requirements.txt


**7. Create a new branch**

- Before making any changes, create a new branch to keep your work organized and isolated.
- Run command:

git checkout -b your_branch_name


**8. Add your Python improvements to the code or documentation**

![wired-lineal-1322-python-code-language-hover-pinch (1)](https://github.com/user-attachments/assets/a14a3609-f02b-4aac-bbe7-d081c505672c) 
![wired-lineal-1322-python-code-language-hover-pinch (1)](https://github.com/user-attachments/assets/a14a3609-f02b-4aac-bbe7-d081c505672c) 
![wired-lineal-1322-python-code-language-hover-pinch (1)](https://github.com/user-attachments/assets/a14a3609-f02b-4aac-bbe7-d081c505672c) 
![wired-lineal-1322-python-code-language-hover-pinch (1)](https://github.com/user-attachments/assets/a14a3609-f02b-4aac-bbe7-d081c505672c)

**9. Run tests and ensure all works fine without any breakdowns**

- Navigate into `test` directory:

cd test\

- Run test itself by invoking `pytest` framework:

pytest -v

βœ… ❌ βœ… ❌

βœ… βœ… βœ… βœ…

10. If all tests are passed βœ…βœ…βœ…βœ… then create commits and push changes

11. Open your king Pull Request πŸ‘‡πŸ‘‡πŸ‘‡

alt text

πŸ‘ πŸ‘ πŸ‘

12. Congratulations, you have done it.

© 2024 by Nazar Pichak.