lukhed-basic-utils 1.0.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/PKG-INFO +1 -1
  2. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/githubCommon.py +75 -20
  3. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils.egg-info/PKG-INFO +1 -1
  4. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils.egg-info/SOURCES.txt +0 -1
  5. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/setup.py +1 -1
  6. lukhed_basic_utils-1.0.0/lukhed_basic_utils/commonCommon.py +0 -9
  7. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/LICENSE +0 -0
  8. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/README.md +0 -0
  9. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/__init__.py +0 -0
  10. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/classCommon.py +0 -0
  11. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/fileCommon.py +0 -0
  12. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/listWorkCommon.py +0 -0
  13. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/mathCommon.py +0 -0
  14. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/osCommon.py +0 -0
  15. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/requestsCommon.py +0 -0
  16. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/stringCommon.py +0 -0
  17. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils/timeCommon.py +0 -0
  18. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils.egg-info/dependency_links.txt +0 -0
  19. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils.egg-info/requires.txt +0 -0
  20. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/lukhed_basic_utils.egg-info/top_level.txt +0 -0
  21. {lukhed_basic_utils-1.0.0 → lukhed_basic_utils-1.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lukhed_basic_utils
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: A collection of basic utility functions
5
5
  Home-page: https://github.com/lukhed/lukhed_basic_utils
6
6
  Author: lukhed
@@ -1,6 +1,5 @@
1
1
  from lukhed_basic_utils import osCommon as osC
2
2
  from lukhed_basic_utils import fileCommon as fC
3
- from lukhed_basic_utils import commonCommon as cC
4
3
  from github import Github
5
4
  from github.Repository import Repository
6
5
  from github.GithubException import UnknownObjectException
@@ -8,7 +7,7 @@ import json
8
7
  from typing import Optional
9
8
 
10
9
  class GithubHelper:
11
- def __init__(self, project='your_project_name', repo_name=None):
10
+ def __init__(self, project='your_project_name', repo_name=None, set_config_directory=None):
12
11
  """
13
12
  A helper class for interacting with GitHub repositories, handling authentication,
14
13
  and various file operations within a repository.
@@ -24,6 +23,9 @@ class GithubHelper:
24
23
  'your_project_name'. Project names are not case sensitive.
25
24
  repo_name (str, optional): Name of the repository to activate immediately
26
25
  after instantiation. Defaults to None.
26
+ set_config_directory (str, optional): Full path to the directory that contains your GithubHelper config
27
+ file (token file). Default is None and this class will create a directory in your working directory
28
+ called 'lukhedConfig' to store the GithubHelper config file.
27
29
 
28
30
  Attributes:
29
31
  _resource_dir (str): Path to the lukhed config directory.
@@ -40,8 +42,15 @@ class GithubHelper:
40
42
  """
41
43
 
42
44
  # Check setup upon instantiation
43
- cC.check_create_lukhed_config_path()
44
- self._resource_dir = cC.get_lukhed_config_path()
45
+ if set_config_directory is None:
46
+ osC.check_create_dir_structure(['lukhedConfig'])
47
+ self._resource_dir = osC.create_file_path_string(['lukhedConfig'])
48
+ else:
49
+ self._resource_dir = set_config_directory
50
+ if not osC.check_if_dir_exists(self._resource_dir):
51
+ print(f"ERROR: The config directory '{set_config_directory}' does not exist. Exiting...")
52
+ quit()
53
+
45
54
  self._github_config_file = osC.append_to_dir(self._resource_dir, 'githubConfig.json')
46
55
  self._github_config = []
47
56
  self.user = None
@@ -55,7 +64,7 @@ class GithubHelper:
55
64
 
56
65
 
57
66
  ###################
58
- # Setup/COnfig
67
+ # Setup/Config
59
68
  ###################
60
69
  def _check_setup(self, project):
61
70
  need_setup = True
@@ -77,9 +86,20 @@ class GithubHelper:
77
86
  self._prompt_for_setup()
78
87
 
79
88
  def _activate_project(self, project):
80
- projects = [x['project'].lower() for x in self._github_config]
81
- project = project.lower()
89
+ try:
90
+ projects = [x['project'].lower() for x in self._github_config]
91
+ except Exception as e:
92
+ input((f"ERROR: Error while trying to parse the config file. It may be corrupt."
93
+ "You can delete the config directory and go through setup again. Press any button to quit."))
94
+ quit()
82
95
 
96
+ try:
97
+ project = project.lower()
98
+ except Exception as e:
99
+ input((f"ERROR: Error while trying to parse project name '{project}'. Try another project name. "
100
+ "Press any button to quit."))
101
+ quit()
102
+
83
103
  if project in projects:
84
104
  # Get the index of the item
85
105
  index = projects.index(project)
@@ -141,6 +161,10 @@ class GithubHelper:
141
161
  ###################
142
162
  # Repo Helpers
143
163
  ###################
164
+ def _activate_repo(self, repo_name):
165
+ self.repo = self._gh_object.get_repo(self.user + "/" + repo_name)
166
+ print(f"INFO: {repo_name} repo was activated")
167
+
144
168
  def _parse_repo_dir_list_input(self, repo_dir_list):
145
169
  if repo_dir_list is None:
146
170
  repo_path = ""
@@ -161,18 +185,48 @@ class GithubHelper:
161
185
 
162
186
  def _set_repo(self, repo_name):
163
187
  try:
164
- self.repo = self._gh_object.get_repo(self.user + "/" + repo_name)
165
- print(f"INFO: {repo_name} repo was activated")
188
+ self._activate_repo(repo_name)
166
189
  return True
167
190
  except Exception as e:
168
- print((f"ERROR: Error trying to set the repo to {repo_name}. Does this repo exist on your account? "
169
- f"Use the method 'get_list_of_repo_names' to see the repos in your active project."
191
+ print((f"ERROR: Error trying to set repo to {repo_name}. Maybe the repo does not exist in your account. "
170
192
  f"See the full error below:\n{e}"))
193
+ create_repo = input(f"Do you want to create a private repo named {repo_name}? (y/n) ")
194
+ if create_repo == 'y':
195
+ if self.create_repo(repo_name, private=True):
196
+ self._activate_repo(repo_name)
171
197
 
172
198
  def _get_repo_contents(self, repo_path):
173
199
  contents = self.repo.get_contents(repo_path)
174
200
  return contents
175
201
 
202
+ def create_repo(self, repo_name, description="Repo created by lukhed-basic-utils", private=True):
203
+ """
204
+ Creates a new repository on GitHub.
205
+
206
+ Parameters:
207
+ repo_name (str): The name of the repository to create.
208
+ description (str, optional): A brief description of the repository.
209
+ private (bool, optional): Determines whether the repository should be private.
210
+ Defaults to True (private repository).
211
+
212
+ Returns:
213
+ bool: True if the repository was created successfully, False otherwise.
214
+
215
+ Example:
216
+ >>> success = obj.create_repo("my-new-repo", description="A test repo", private=True)
217
+ """
218
+ try:
219
+ repo = self._gh_object.get_user().create_repo(
220
+ name=repo_name,
221
+ description=description,
222
+ private=private
223
+ )
224
+ print(f"Repository '{repo.name}' created successfully at {repo.html_url}")
225
+ return True
226
+ except Exception as e:
227
+ print(f"An error occurred: {e}")
228
+ return False
229
+
176
230
  def get_list_of_repo_names(self, print_names=False):
177
231
  """
178
232
  Returns a list of repo names available in the active project. Optionally prints the list to console.
@@ -269,14 +323,14 @@ class GithubHelper:
269
323
  else:
270
324
  return contents
271
325
 
272
- def create_file(self, content, path_as_list_or_str=None, commit_message="no message"):
326
+ def create_file(self, content, path_as_list_or_str, commit_message="no message"):
273
327
  """
274
328
  Creates a new file in the repository with the specified content.
275
329
 
276
330
  Parameters:
277
331
  content (str | dict): The content to upload. If dict, it will be converted to JSON.
278
- path_as_list_or_str (list | str, optional): Path to the file in the repository,
279
- either as a list of directory segments or a single string. Defaults to None.
332
+ path_as_list_or_str (list | str): Path to the file in the repository,
333
+ either as a list of directory segments or a single string.
280
334
  commit_message (str, optional): Commit message for the new file. Defaults to "no message".
281
335
 
282
336
  Returns:
@@ -293,13 +347,13 @@ class GithubHelper:
293
347
  status = self.repo.create_file(path=repo_path, message=commit_message, content=content)
294
348
  return status
295
349
 
296
- def delete_file(self, path_as_list_or_str=None, commit_message="Delete file"):
350
+ def delete_file(self, path_as_list_or_str, commit_message="Delete file"):
297
351
  """
298
352
  Deletes a file from the repository.
299
353
 
300
354
  Parameters:
301
- path_as_list_or_str (list | str, optional): Path to the file in the repository,
302
- either as a list of directory segments or a single string. Defaults to None.
355
+ path_as_list_or_str (list | str): Path to the file in the repository,
356
+ either as a list of directory segments or a single string.
303
357
  commit_message (str, optional): Commit message for the deletion. Defaults to "Delete file".
304
358
 
305
359
  Returns:
@@ -371,13 +425,13 @@ class GithubHelper:
371
425
 
372
426
  return status
373
427
 
374
- def file_exists(self, repo_dir_list=None):
428
+ def file_exists(self, repo_dir_list):
375
429
  """
376
430
  Checks if a file exists in the repository.
377
431
 
378
432
  Parameters:
379
- repo_dir_list (list | str, optional): Path to the file in the repository,
380
- either as a list of directory segments or a single string. Defaults to None.
433
+ repo_dir_list (list | str): Path to the file in the repository,
434
+ either as a list of directory segments or a single string.
381
435
 
382
436
  Returns:
383
437
  bool: True if the file exists, False otherwise.
@@ -388,4 +442,5 @@ class GithubHelper:
388
442
  return False
389
443
  else:
390
444
  return True
445
+
391
446
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lukhed-basic-utils
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: A collection of basic utility functions
5
5
  Home-page: https://github.com/lukhed/lukhed_basic_utils
6
6
  Author: lukhed
@@ -3,7 +3,6 @@ README.md
3
3
  setup.py
4
4
  lukhed_basic_utils/__init__.py
5
5
  lukhed_basic_utils/classCommon.py
6
- lukhed_basic_utils/commonCommon.py
7
6
  lukhed_basic_utils/fileCommon.py
8
7
  lukhed_basic_utils/githubCommon.py
9
8
  lukhed_basic_utils/listWorkCommon.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="lukhed_basic_utils",
5
- version="1.0.0",
5
+ version="1.2.0",
6
6
  description="A collection of basic utility functions",
7
7
  long_description=open("README.md").read(),
8
8
  long_description_content_type="text/markdown",
@@ -1,9 +0,0 @@
1
- from lukhed_basic_utils import osCommon as osC
2
-
3
- config_dir = 'lukhedConfig'
4
-
5
- def check_create_lukhed_config_path():
6
- osC.check_create_dir_structure([config_dir])
7
-
8
- def get_lukhed_config_path():
9
- return osC.create_file_path_string([config_dir])