10
10
import time
11
11
import typing
12
12
from dataclasses import dataclass
13
- import luadata
14
13
15
14
import click
15
+ import luadata
16
16
from mdutils .mdutils import MdUtils
17
17
from selenium .webdriver import Chrome , ChromeOptions
18
18
from selenium .webdriver .common .by import By
@@ -641,36 +641,12 @@ def greater_than(a: ColorSpec, b: ColorSpec) -> bool:
641
641
logging .debug (f"after dedup: { [str (s ) for s in specs_set ]} " )
642
642
return list (specs_set )
643
643
644
- def build (self ) -> None :
645
- self ._download ()
646
- # dedup candidates
647
- deduped_specs = self ._dedup ()
648
-
649
- total = 0
650
- for spec in ColorSpec .all ():
651
- if spec not in deduped_specs :
652
- logging .debug (f"remove for duplicate - repo:{ spec } " )
653
- spec .remove ()
654
- else :
655
- total += 1
656
-
657
- md = MdUtils (file_name = "COLORSCHEMES" , title = f"ColorSchemes List ({ total } )" )
658
- all_specs = sorted (ColorSpec .all (), key = lambda s : s .github_stars , reverse = True )
659
- for i , spec in enumerate (all_specs ):
660
- logging .info (f"collect spec-{ i } :{ spec } " )
661
- color_names = spec .get_vim_color_names ()
662
- color_names = sorted (color_names )
663
- md .new_line (
664
- f"- { md .new_inline_link (link = spec .url , text = spec .handle )} (stars: { spec .github_stars } , last update: { date_tostring (spec .last_git_commit )} )"
665
- )
666
- for cname in color_names :
667
- md .new_line (f" - { cname } " )
668
- md .create_md_file ()
669
-
644
+ def _build_lua_specs (self , all_specs : list [ColorSpec ]) -> None :
670
645
lspecs = {}
671
- lspecsbycolorname = {}
672
- lspecsbygitpath = {}
646
+ lspecs_by_colorname = {}
647
+ lspecs_by_gitpath = {}
673
648
lcolornames = []
649
+
674
650
for i , spec in enumerate (all_specs ):
675
651
logging .info (f"dump lua specs for spec-{ i } :{ spec } " )
676
652
lcolors = sorted (spec .get_vim_color_names ())
@@ -686,16 +662,68 @@ def build(self) -> None:
686
662
ColorSpec .COLOR_NAMES : lcolors ,
687
663
}
688
664
lspecs [spec .handle ] = lobj
689
- lspecsbygitpath [spec .git_path ] = lobj
665
+ lspecs_by_gitpath [spec .git_path ] = lobj
690
666
for j , color in enumerate (lcolors ):
691
667
lcolornames .append (color )
692
- lspecsbycolorname [color ] = lobj
668
+ lspecs_by_colorname [color ] = lobj
693
669
694
670
lcolornames = sorted (lcolornames , key = lambda c : c .lower ())
695
- luadata .write ("lua/colorbox/meta/specs.lua" , lspecs , encoding = "utf-8" , indent = " " , prefix = "return " )
696
- luadata .write ("lua/colorbox/meta/specs_by_colorname.lua" , lspecsbycolorname , encoding = "utf-8" , indent = " " , prefix = "return " )
697
- luadata .write ("lua/colorbox/meta/specs_by_gitpath.lua" , lspecsbygitpath , encoding = "utf-8" , indent = " " , prefix = "return " )
698
- luadata .write ("lua/colorbox/meta/colornames.lua" , lcolornames , encoding = "utf-8" , indent = " " , prefix = "return " )
671
+ luadata .write (
672
+ "lua/colorbox/meta/specs.lua" ,
673
+ lspecs ,
674
+ encoding = "utf-8" ,
675
+ indent = " " ,
676
+ prefix = "return " ,
677
+ )
678
+ luadata .write (
679
+ "lua/colorbox/meta/specs_by_colorname.lua" ,
680
+ lspecs_by_colorname ,
681
+ encoding = "utf-8" ,
682
+ indent = " " ,
683
+ prefix = "return " ,
684
+ )
685
+ luadata .write (
686
+ "lua/colorbox/meta/specs_by_gitpath.lua" ,
687
+ lspecs_by_gitpath ,
688
+ encoding = "utf-8" ,
689
+ indent = " " ,
690
+ prefix = "return " ,
691
+ )
692
+ luadata .write (
693
+ "lua/colorbox/meta/colornames.lua" ,
694
+ lcolornames ,
695
+ encoding = "utf-8" ,
696
+ indent = " " ,
697
+ prefix = "return " ,
698
+ )
699
+
700
+ def _build_md_list (self , all_specs : list [ColorSpec ]) -> None :
701
+ total = len (all_specs )
702
+ md = MdUtils (file_name = "COLORSCHEMES" , title = f"ColorSchemes List ({ total } )" )
703
+ for i , spec in enumerate (all_specs ):
704
+ logging .info (f"collect spec-{ i } :{ spec } " )
705
+ color_names = spec .get_vim_color_names ()
706
+ color_names = sorted (color_names )
707
+ md .new_line (
708
+ f"- { md .new_inline_link (link = spec .url , text = spec .handle )} (stars: { spec .github_stars } , last update: { date_tostring (spec .last_git_commit )} )"
709
+ )
710
+ for cname in color_names :
711
+ md .new_line (f" - { cname } " )
712
+ md .create_md_file ()
713
+
714
+ def build (self ) -> None :
715
+ self ._download ()
716
+ # dedup candidates
717
+ deduped_specs = self ._dedup ()
718
+
719
+ for spec in ColorSpec .all ():
720
+ if spec not in deduped_specs :
721
+ logging .debug (f"remove for duplicate - repo:{ spec } " )
722
+ spec .remove ()
723
+
724
+ all_specs = sorted (ColorSpec .all (), key = lambda s : s .github_stars , reverse = True )
725
+ self ._build_md_list (all_specs )
726
+ self ._build_lua_specs (all_specs )
699
727
700
728
701
729
@click .command ()
0 commit comments