Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DB schema and config files import #32

Merged
merged 8 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test-clir.yml
Original file line number Diff line number Diff line change
@@ -20,6 +20,12 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install xclip
if: runner.os == 'Linux' # Run only if the OS is Linux (Ubuntu)
run: |
sudo apt-get update
sudo apt-get install xorg openbox
sudo apt-get install -y xclip xsel
- name: Install poetry
run: |
python -m pip install --upgrade pip
Empty file added clir/config/__init__.py
Empty file.
Empty file added clir/config/db/__init__.py
Empty file.
9 changes: 5 additions & 4 deletions clir/utils/config.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from clir.utils.db import create_database
from clir.utils.core import get_commands
from clir.utils.db import insert_command_db
import importlib.resources

config_directory = "clir/config/"
env_path = Path('~').expanduser() / Path(".clir")
@@ -70,11 +71,11 @@ def copy_config_files():

# Check if the file already exists
for file in files:
with importlib.resources.open_text('clir.config', 'clir.conf') as f:
conf = f.read()
with open(f"{env_path}/{file}", "w") as file:
file.write(conf)

source_file = f"{config_directory}/{file}"
destination_file = f"{env_path}/{file}"

shutil.copyfile(source_file, destination_file)
print(f"Copying {file} file to {env_path}")

def init_config():
8 changes: 4 additions & 4 deletions clir/utils/db.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
from pathlib import Path
import datetime
import shutil
import importlib.resources

# Specify the directory and file name
schema_directory = "clir/config/db/"
@@ -72,10 +73,9 @@ def create_database(database_name = db_file, schema_file = sql_schema_path):
cursor = conn.cursor()

# Read and execute SQL statements from the schema file
with open(schema_file, 'r') as schema_file:
schema_sql = schema_file.read()
#print(schema_sql)
cursor.executescript(schema_sql)
with importlib.resources.open_text('clir.config.db', 'schema.sql') as f:
schema = f.read()
cursor.executescript(schema)

# Commit the changes
conn.commit()
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "clir"
version = "0.6.3"
version = "0.6.0"
description = "A clear and fast way to store and recover your commands"
authors = ["Elkin Aguas <[email protected]>"]
license = "MIT License"
@@ -18,9 +18,6 @@ click = "^8.1.7"
rich-click = "^1.7.0"
textual = "^0.47.1"

[tool.poetry.package.include]
include = "clir/config/db/schema.sql"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"