Skip to content

Commit

Permalink
separated the code to create a new function with the org level direct…
Browse files Browse the repository at this point in the history
…ory so that I can use that separately to create the path for a csv file that summarizes the org level details
  • Loading branch information
geekygirldawn committed Dec 1, 2023
1 parent ace0308 commit da71901
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions utils/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@
""" This file contains several functions that perform various file operations
"""

def output_path(repo_name, org_name):
def create_path_str(org_name):
""" Creates the path string where files will be located
Parameters
----------
org_name : str
Returns
-------
path_str : str
"""
import datetime
from os.path import dirname, join
from pathlib import Path
from utils.date_calcs import get_last_month

today = datetime.date.today()
last_month = get_last_month()
current_year_month = str(last_month.year) + '-' + '{:02d}'.format(last_month.month)

current_dir = dirname(dirname(__file__)) # the double dirname is equivalent to ../
rel_path = './output/' + current_year_month + '/' + org_name
path_str = join(current_dir, rel_path)
Path(path_str).mkdir(parents=True, exist_ok=True)

return path_str


def output_path(repo_name, org_name):
""" Creates the path string including repo where .png files will be located
Parameters
----------
repo_name : str
Expand All @@ -17,17 +46,13 @@ def output_path(repo_name, org_name):
path : str
"""
import datetime
from os.path import dirname, join
from pathlib import Path
from utils.date_calcs import get_last_month

today = datetime.date.today()
last_month = get_last_month()
current_year_month = str(last_month.year) + '-' + '{:02d}'.format(last_month.month)
path_str = create_path_str(org_name)

current_dir = dirname(dirname(__file__)) # the double dirname is equivalent to ../
rel_path = './output/' + current_year_month + '/' + org_name + '/' + repo_name
rel_path = path_str + '/' + repo_name
path = join(current_dir, rel_path)
Path(path).mkdir(parents=True, exist_ok=True)

Expand All @@ -51,4 +76,4 @@ def output_filename(repo_name, org_name, metric_string):

filename = path + '/' + repo_name + '_' + metric_string + '.png'

return filename
return filename

0 comments on commit da71901

Please sign in to comment.