Skip to content

Commit

Permalink
create missing icons list
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed May 12, 2021
1 parent fb05228 commit 265c866
Show file tree
Hide file tree
Showing 3 changed files with 646 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Translations are now managed on Crowdin. Go to the [Authenticator Pro Crowdin pr

## Icons

If you wish to contribute more icons to the application, the procedure is as follows:
If you'd like to contribute some icons, check the [missing icons list](./extra/missing_icons.txt) for some that might need adding. There may be duplicates, so check first!

To add an icon to the project the procedure is as follows:

* Fork the repo

Expand All @@ -27,6 +29,8 @@ If you wish to contribute more icons to the application, the procedure is as fol

* Optional: To complete the process and to build / test the project with the new icons, run the `generate_icons.py` script in the extras directory. This will generate the DPI variants, reference them in the csproj file and icon map.

* Remove the entry from the [missing icons list](./extra/missing_icons.txt) if it exists.

* Commit changes (if the above script was run, commit the changes to the `AuthenticatorPro.Droid.Shared.csproj` and `IconMap.cs` files and add the generated drawables)

* Create a pull request with your changes
Expand Down
85 changes: 85 additions & 0 deletions extra/find_missing_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

import os
import re
import yaml

TWOFACTORAUTH_REPO = "https://github.com/2factorauth/twofactorauth.git"
TEMP_DIR = "/tmp/twofactorauth"

DARK_SUFFIX = "_dark"
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
MAIN_DIR = os.path.realpath(os.path.join(CURRENT_DIR, os.pardir))


def simplify_name(name: str) -> str:
name = name.lower()
name = re.sub(r"[^a-z0-9]", "", name)
name = name.strip()

return name


def clone_twofactorauth():
os.system(f"git clone {TWOFACTORAUTH_REPO} {TEMP_DIR}")


def clean():
os.system(f"rm -rf {TEMP_DIR}")


def get_available_icons() -> list:
data_dir = f"{TEMP_DIR}/_data"
files = os.listdir(data_dir)

result = []

for category_file in files:

if category_file[-3:] != "yml":
continue

with open(f"{data_dir}/{category_file}", "r") as file:
obj = yaml.safe_load(file)

if "websites" not in obj:
continue

for site in obj["websites"]:

if "tfa" not in site or "totp" not in site["tfa"]:
continue

result.append(site["name"])

return result


def get_existing_icons() -> list:
result = os.listdir(f"{MAIN_DIR}/icons")
result = map(lambda i: i[:-4], result)
result = filter(lambda i: i[-len(DARK_SUFFIX):] != DARK_SUFFIX, result)
return list(result)


def get_missing_icons() -> list:
available = get_available_icons()
existing = get_existing_icons()

missing = [i for i in available if simplify_name(i) not in existing]
return missing


def main():
try:
clone_twofactorauth()
missing = get_missing_icons()
finally:
clean()

for i in missing:
print(i)


if __name__ == "__main__":
main()
Loading

0 comments on commit 265c866

Please sign in to comment.