simonduerr commited on
Commit
8df3557
·
1 Parent(s): 958b4cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -97,33 +97,43 @@ def process_and_create_pull(icon_files,category, new_cateogry_check, new_categor
97
  sha=index_file.sha,
98
  branch=branch_name
99
  )
100
- all_files = []
101
- contents = site.get_contents("static/icons/{license}/{category}/{author}/")
102
- while contents:
103
- file_content = contents.pop(0)
104
- if file_content.type == "dir":
105
- contents.extend(site.get_contents(file_content.path))
106
- else:
107
- file = file_content
108
- all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))
109
- print("files in directory:", all_files)
 
110
  for file in icon_files:
111
  #get file content from filesystem
112
  with open(file.name, 'r') as fp:
113
  file_content = fp.read()
114
  filename = os.path.basename(file.name).replace(" ", "_")
115
  git_file = f'static/icons/{license}/{category}/{author}/{filename}'
116
- if git_file in all_files:
117
- contents = site.get_contents(git_file)
118
- site.update_file(contents.path, f'update {filename}', file_content, contents.sha, branch=branch_name)
119
- print(git_file + ' UPDATED')
120
- else:
121
  site.create_file(
122
  path=git_file,
123
  message=f'create {filename}',
124
  content=file_content,
125
  branch=branch_name
126
  )
 
 
 
 
 
 
 
 
 
 
 
 
127
  pull = create_pull_request(site,branch_name, github_user)
128
  return f"""<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.4/flowbite.min.css" rel="stylesheet" />
129
  <div class="flex p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-200 " role="alert">
 
97
  sha=index_file.sha,
98
  branch=branch_name
99
  )
100
+ #all_files = []
101
+ #contents = site.get_contents("static/icons/{license}/{category}/{author}/")
102
+ #print(contents)
103
+ #while contents:
104
+ # file_content = contents.pop(0)
105
+ # if file_content.type == "dir":
106
+ # contents.extend(site.get_contents(file_content.path))
107
+ # else:
108
+ # file = file_content
109
+ # all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))
110
+ #print("files in directory:", all_files)
111
  for file in icon_files:
112
  #get file content from filesystem
113
  with open(file.name, 'r') as fp:
114
  file_content = fp.read()
115
  filename = os.path.basename(file.name).replace(" ", "_")
116
  git_file = f'static/icons/{license}/{category}/{author}/{filename}'
117
+
118
+ try:
 
 
 
119
  site.create_file(
120
  path=git_file,
121
  message=f'create {filename}',
122
  content=file_content,
123
  branch=branch_name
124
  )
125
+ except GithubException:
126
+ print(git_file, "already exists, updating")
127
+ contents = site.get_contents(git_file)
128
+ site.update_file(
129
+ path=git_file,
130
+ message=f'update {filename}',
131
+ content=file_content,
132
+ sha=contents.sha,
133
+ branch=branch_name
134
+ )
135
+
136
+
137
  pull = create_pull_request(site,branch_name, github_user)
138
  return f"""<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.4/flowbite.min.css" rel="stylesheet" />
139
  <div class="flex p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-200 " role="alert">