-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f9a285
commit fa9b22a
Showing
7 changed files
with
105 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
__version__ = "0.1.0" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
config_file = Path.home() / ".githubkeep.ini" | ||
config_text = ''' | ||
[DEFAULT] | ||
editor = "vim" | ||
cache_repos = 1 | ||
# how many minutes should each repo be kept in cache | ||
cache_delta = 3 | ||
cache_loc = "" | ||
github_token = "" | ||
gitlab_token = "" | ||
[proxy_settings] | ||
https_proxy = "" | ||
http_proxy = "" | ||
''' | ||
if not os.path.exists(config_file): | ||
with open(config_file, "w") as fh: | ||
fh.write(config_text) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
import os | ||
import configparser | ||
from datetime import datetime | ||
from datetime import timedelta | ||
from pathlib import Path | ||
|
||
GITHUB_API = "https://api.github.com/repos/{owner}/{repo}/tarball/master" | ||
EDITORS = ["vim", "vi", "nvim", "nano", "code", "emacs"] | ||
|
||
|
||
def config(cfg_file=".githubkeep.conf"): | ||
"""set global config setting""" | ||
# TODO(unrahul): change to ini logger | ||
config_file = Path.home() / cfg_file | ||
template = "{}={}" | ||
exists = os.path.isfile(config_file) | ||
if exists: | ||
with open(config_file, "r") as rh: | ||
line = rh.readline() | ||
count = int(line.split("=")[1]) | ||
count -= 1 | ||
else: | ||
count = 5 | ||
with open(config_file, "w") as fh: | ||
fh.writelines(template.format("count_till_cache_delete", count)) | ||
fh.flush() | ||
return config_file | ||
class Config: | ||
def __init__(self, cfg_file=".githubkeep.ini"): | ||
self.config_file = Path.home() / cfg_file | ||
self.config = configparser.ConfigParser() | ||
self.config.read(self.config_file) | ||
|
||
def cache_repo(self, name): | ||
"""update repo with name, url and remove_by info.""" | ||
if not self.config.has_section(name): | ||
self.config.add_section(name) | ||
self.config.set( | ||
name, | ||
"remove_by", | ||
( | ||
datetime.now() | ||
+ timedelta(minutes=self.config["DEFAULT"].getint("CACHE_DELTA")) | ||
).strftime("%Y%m%d-%H%M%S"), | ||
) | ||
with open(self.config_file, "w") as configfile: | ||
self.config.write(configfile) | ||
|
||
def is_repo_stale(self, name): | ||
"""check if the repo is ready to be deleted.""" | ||
if self.config.has_section(name): | ||
remove_by = self.config[name].get("remove_by") | ||
remove_by = datetime.strptime(remove_by, "%Y%m%d-%H%M%S") | ||
if remove_by < datetime.now(): | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
|
||
|
||
def init_dir(home_dir) -> Path: | ||
"""create a dir to save the downloaded files.""" | ||
home_dir.mkdir(parents=True, exist_ok=True) | ||
return home_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters