Skip to content

Commit

Permalink
[RFR] adjust Intellij file path (#123)
Browse files Browse the repository at this point in the history
* adjust Intellij file path

Signed-off-by: nhamza <[email protected]>

* remove unused import

Signed-off-by: nhamza <[email protected]>

* apply requested changes

Signed-off-by: nhamza <[email protected]>

* apply requested changes

Signed-off-by: nhamza <[email protected]>

---------

Signed-off-by: nhamza <[email protected]>
  • Loading branch information
Neilhamza authored Mar 3, 2024
1 parent 0705fb3 commit bdbec62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/fixtures/ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def setup_intellij(intellij_config, config):
"""
intellij = Intellij()
ide_path = intellij_config["ide_path"]
ide_version = intellij.get_ide_version(ide_path)
path = ide_path + f"/{ide_version}/bin/idea.sh"
path = os.path.join(ide_path, "bin", "idea.sh")
intellij.open_application(path)
intellij.set_default_timeout(timeout=config["timeout_in_seconds"])
time.sleep(5)
Expand Down
11 changes: 8 additions & 3 deletions src/models/IDE/Intellij.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
import logging
import os
import re
import subprocess
import time

from src.models.application import Application
from src.models.configuration.configurations_object import ConfigurationsObject
from src.utils.general import read_file


class Intellij(Application):
Expand All @@ -23,8 +24,12 @@ def __init__(self):
self.configurations = []

def get_ide_version(self, ide_directory):
pattern = re.compile(r"\d{3}\.\d{4}\.\d{2}")
return [name for name in os.listdir(ide_directory) if pattern.search(name) is not None][0]
info_file_path = os.path.join(ide_directory, "product-info.json")
file_contents = read_file(info_file_path)
if file_contents is not None:
info_data = json.loads(file_contents)
return info_data.get("version")
return None

def close_ide(self):
"""
Expand Down
10 changes: 7 additions & 3 deletions src/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def write_data_to_file(file_path, content):


def read_file(filename):
with open(filename, "r") as file:
contents = file.read()
return contents
try:
with open(filename, "r") as file:
contents = file.read()
return contents
except FileNotFoundError:
print(f"File not found: {filename}")
return None


def assert_valid_csv_file(file_path, **kwargs):
Expand Down

0 comments on commit bdbec62

Please sign in to comment.