Skip to content

Commit

Permalink
hosting readme template on github
Browse files Browse the repository at this point in the history
  • Loading branch information
mccallc committed Nov 17, 2024
1 parent f812843 commit 61b05c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
13 changes: 6 additions & 7 deletions dvcurator/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def load_config(self, path=None):
self.dropbox.set(config['default']['dropbox'])
self.dropbox_entry.config(text=os.path.split(self.dropbox.get())[1])
print("Loaded settings: " + path)
print("Curation repo: " + self.curation_repo.get())

# function to save settings as .ini file
def save_config_as(self):
Expand All @@ -109,11 +110,11 @@ def save_config(self, path=None):
path = self.local_ini if not path else path
import dvcurator.hosts
if (self.dataverse_host.get() == ""):
self.dataverse_host.set(dvcurator.hosts.qdr_dataverse"")
self.dataverse_host.set(dvcurator.hosts.qdr_dataverse)
if (self.curation_repo.get() == ""):
self.curation_repo.set(dvcurator.hosts.curation_repo)
if (self.github_org.get() == ""):
self.github_org.set(dvcurator.host)
self.github_org.set(dvcurator.hosts.github_org)

import configparser
config = configparser.ConfigParser()
Expand Down Expand Up @@ -299,7 +300,7 @@ def create_readme(self):

self.disable_buttons()
t = threading.Thread(target=dvcurator.readme.generate_readme,
args=(self.metadata, os.path.join(self.subfolder_path, "QDR Prepared"), self.dv_token.get()))
args=(self.metadata, os.path.join(self.subfolder_path, "QDR Prepared"), self.dv_token.get(), self.curation_repo.get()))
t.start()
self.schedule_check(t)

Expand Down Expand Up @@ -357,7 +358,7 @@ def __init__(self, parent, *args, **kwargs):

# Settings
self.github_org = tk.StringVar()
self.curator_repo = tk.StringVar()
self.curation_repo = tk.StringVar()
self.dataverse_host = tk.StringVar()

settings = tk.Frame(self)
Expand Down Expand Up @@ -418,6 +419,7 @@ def __init__(self, parent, *args, **kwargs):
# Set working directory to the folder the executable is in
self.local_ini = os.path.join(os.path.dirname(sys.executable), "dvcurator.ini")
icon = os.path.join(sys._MEIPASS, "assets", "qdr.ico")
parent.iconbitmap(bitmap=icon)
else:
self.local_ini = os.path.join(os.getcwd(), "dvcurator.ini")
from pkg_resources import resource_filename
Expand All @@ -426,13 +428,10 @@ def __init__(self, parent, *args, **kwargs):
if os.path.exists(self.local_ini):
self.load_config(self.local_ini)

parent.iconbitmap(default=icon)

# save config on exit
parent.protocol("WM_DELETE_WINDOW", self.close_window)



def main():
root=tk.Tk()
root.resizable(width=False, height=False)
Expand Down
2 changes: 1 addition & 1 deletion dvcurator/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def find_pdfs(path):
pdfs = []
for root, dirs, files in os.walk(path):
for name in files:
if re.search('\.(pdf|PDF)', name):
if re.search('.(pdf|PDF)', name):
pdfs += [os.path.join(root, name)]

return pdfs
Expand Down
33 changes: 19 additions & 14 deletions dvcurator/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def clean_html_tags(text):
clean_text = re.sub(tags, '', text)
return clean_text

def generate_readme(metadata, folder, token=None):
def generate_readme(metadata, folder, token=None, repo=None):
"""
Generate README.txt file.
Expand All @@ -31,8 +31,8 @@ def generate_readme(metadata, folder, token=None):
"""
from string import Template
from pkg_resources import resource_filename
import os, dvcurator.dataverse, dvcurator.fs, dvcurator.rename, sys, re, unicodedata
import os, dvcurator.dataverse, dvcurator.fs, dvcurator.rename, dvcurator.hosts
import requests, sys, re, unicodedata
citation = dvcurator.dataverse.get_citation(metadata)
folder = dvcurator.fs.current_step(folder)

Expand Down Expand Up @@ -79,17 +79,22 @@ def generate_readme(metadata, folder, token=None):
}

# the location of the template differs if this is a compiled pyinstaller file or run directly
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
path = os.path.join(sys._MEIPASS, "assets", "README.txt")
else:
path = resource_filename("dvcurator", "assets/README.txt")


## Download readme template from github
host = "https://raw.githubusercontent.com/"
repo = dvcurator.hosts.curation_repo if not repo else repo
readme_url = host + repo + "/refs/heads/master/README_template.txt"

response = requests.get(readme_url)
response.raise_for_status()
readme_template = response.text
print("Downloaded README template...")

# write the actual file
with open(path, 'r') as f:
src = Template(f.read())
text = src.safe_substitute(d)
with open(new_path, 'w', encoding="utf-8") as n:
n.write(text)
print("Written: " + new_path)
src = Template(readme_template)
text = src.safe_substitute(d)
with open(new_path, 'w', encoding="utf-8") as n:
n.write(text)
print("Written: " + new_path)

return new_path

0 comments on commit 61b05c7

Please sign in to comment.