fbup 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +11 -0
- data/README.md +37 -0
- data/Rakefile +30 -0
- data/bin/fbup +16 -0
- data/config/openfootball.csv +117 -0
- data/lib/fbup/github.rb +115 -0
- data/lib/fbup/github_config.rb +97 -0
- data/lib/fbup/main.rb +165 -0
- data/lib/fbup/version.rb +24 -0
- data/lib/fbup.rb +27 -0
- metadata +124 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: d55ede42bbe3e933365193d25054464d9226d1a5743dc9b4919ce47760faa68d
         | 
| 4 | 
            +
              data.tar.gz: 2c759f0719ceed561a02d25818141cb57625ef60ca99f1f294c5e80e0b185d05
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: ea4c01a1e01290360ebe48028225745c6b33d6ad2196af66846f6287a1a0bd2c6713c7026127a281caade87d8b2488c27c09e0c61d54a7992322d0b334b33d12
         | 
| 7 | 
            +
              data.tar.gz: 5b6afe253dcabb81e23918dbb257104dcb3c25446f3a5ffdcd3e12553fd5dcf69995018f4476903c3ae5844fc00e3969afb84c0634d390063b743011553d7419
         | 
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/Manifest.txt
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            # fbup - (auto-)update machinery for footbal match schedules & more in football.txt; incl. (auto-sync & commit) support for github openfootball repos & more
         | 
| 2 | 
            +
             
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            * home  :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
         | 
| 5 | 
            +
            * bugs  :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
         | 
| 6 | 
            +
            * gem   :: [rubygems.org/gems/fbup](https://rubygems.org/gems/fbup)
         | 
| 7 | 
            +
            * rdoc  :: [rubydoc.info/gems/fbup](http://rubydoc.info/gems/fbup)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             | 
| 10 | 
            +
            ## Step 0 - Installation Via Gems
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            To install the command-line tool via gems (ruby's package manager) use:
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ```
         | 
| 15 | 
            +
            $ gem install fbup
         | 
| 16 | 
            +
            ```
         | 
| 17 | 
            +
             | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Try in your shell / terminal:
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ```
         | 
| 24 | 
            +
            $ fbup -h
         | 
| 25 | 
            +
            ```
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            resulting in:
         | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
| 30 | 
            +
            ...
         | 
| 31 | 
            +
             | 
| 32 | 
            +
             | 
| 33 | 
            +
             | 
| 34 | 
            +
            ## Questions? Comments?
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            Yes, you can. More than welcome.
         | 
| 37 | 
            +
            See [Help & Support »](https://github.com/openfootball/help)
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require 'hoe'
         | 
| 2 | 
            +
            require './lib/fbup/version.rb'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
             | 
| 5 | 
            +
            Hoe.spec 'fbup' do
         | 
| 6 | 
            +
              self.version = SportDb::Module::Fbup::VERSION
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              self.summary = "fbup - (auto-)update machinery for footbal match schedules & more in football.txt; incl. (auto-sync & commit) support for github openfootball repos & more"
         | 
| 9 | 
            +
              self.description = summary
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              self.urls = { home: 'https://github.com/sportdb/sport.db' }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              self.author = 'Gerald Bauer'
         | 
| 14 | 
            +
              self.email  = 'gerald.bauer@gmail.com'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              # switch extension to .markdown for gihub formatting
         | 
| 17 | 
            +
              self.readme_file  = 'README.md'
         | 
| 18 | 
            +
              self.history_file = 'CHANGELOG.md'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              self.licenses = ['Public Domain']
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              self.extra_deps = [
         | 
| 23 | 
            +
                   ['sportdb-writers', '>= 0.4.0'],
         | 
| 24 | 
            +
                   ['gitti', '>= 0.6.1'],
         | 
| 25 | 
            +
              ]
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              self.spec_extras = {
         | 
| 28 | 
            +
                required_ruby_version: '>= 3.1.0'
         | 
| 29 | 
            +
              }
         | 
| 30 | 
            +
            end
         | 
    
        data/bin/fbup
    ADDED
    
    
| @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            key,  path
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            at,   austria
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            de,   deutschland
         | 
| 6 | 
            +
            eng,  england
         | 
| 7 | 
            +
            es,   espana
         | 
| 8 | 
            +
            it,   italy
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            fr,   europe/france
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            hu, europe/hungary
         | 
| 13 | 
            +
            gr, europe/greece
         | 
| 14 | 
            +
            pt, europe/portugal
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ch, europe/switzerland
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            tr, europe/turkey
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            is,   europe/iceland
         | 
| 21 | 
            +
            sco,  europe/scotland
         | 
| 22 | 
            +
            ie,  europe/ireland
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            fi,  europe/finland
         | 
| 25 | 
            +
            se,  europe/sweden
         | 
| 26 | 
            +
            no,  europe/norway
         | 
| 27 | 
            +
            dk,  europe/denmark
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            lu,  europe/luxembourg
         | 
| 30 | 
            +
            be,  europe/belgium
         | 
| 31 | 
            +
            nl,  europe/netherlands
         | 
| 32 | 
            +
            cz,  europe/czech-republic
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            sk,   europe/slovakia
         | 
| 35 | 
            +
            hr,  europe/croatia
         | 
| 36 | 
            +
            pl,   europe/poland
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            ro,  europe/romania
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            ua,  europe/ukraine
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ru,  europe/russia
         | 
| 43 | 
            +
             | 
| 44 | 
            +
             | 
| 45 | 
            +
            al,  europe/albania
         | 
| 46 | 
            +
            ad,  europe/andorra
         | 
| 47 | 
            +
            by,  europe/belarus
         | 
| 48 | 
            +
            ba,  europe/bosnia-herzegovina   ## use bosnia-n-herzegovina ??
         | 
| 49 | 
            +
            bg,  europe/bulgaria
         | 
| 50 | 
            +
            cy,  europe/cyprus
         | 
| 51 | 
            +
            ee,  europe/estonia
         | 
| 52 | 
            +
            lv,  europe/latvia
         | 
| 53 | 
            +
            li,  europe/liechtenstein
         | 
| 54 | 
            +
            lt,  europe/lithuania
         | 
| 55 | 
            +
            mk,  europe/north-macedonia
         | 
| 56 | 
            +
            mt,  europe/malta
         | 
| 57 | 
            +
            md,  europe/moldova
         | 
| 58 | 
            +
            me,  europe/montenegro
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            sm,  europe/san-marino
         | 
| 61 | 
            +
            rs,  europe/serbia
         | 
| 62 | 
            +
            si,  europe/slovenia
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            xk,  europe/kosovo
         | 
| 65 | 
            +
            kos, europe/kosovo
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            am,  europe/armenia
         | 
| 68 | 
            +
            az,  europe/azerbaijan
         | 
| 69 | 
            +
            ge,  europe/georgia
         | 
| 70 | 
            +
            fo,  europe/faroe-islands
         | 
| 71 | 
            +
            gi,  europe/gibraltar
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            wal, europe/wales
         | 
| 74 | 
            +
            nir, europe/northern-ireland
         | 
| 75 | 
            +
             | 
| 76 | 
            +
             | 
| 77 | 
            +
             | 
| 78 | 
            +
            uefa.cl,      champions-league
         | 
| 79 | 
            +
            uefa.champs,  champions-league
         | 
| 80 | 
            +
            uefa.el,      champions-league
         | 
| 81 | 
            +
            uefa.europa,  champions-league
         | 
| 82 | 
            +
            uefa.conf,    champions-league
         | 
| 83 | 
            +
            uefa.con,     champions-league
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            euro,       euro
         | 
| 86 | 
            +
             | 
| 87 | 
            +
             | 
| 88 | 
            +
             | 
| 89 | 
            +
            mx, mexico
         | 
| 90 | 
            +
             | 
| 91 | 
            +
             | 
| 92 | 
            +
            ar, south-america/argentina
         | 
| 93 | 
            +
            br, south-america/brazil
         | 
| 94 | 
            +
            co, south-america/colombia
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            copa.l,  south-america/copa-libertadores
         | 
| 97 | 
            +
            copa.s,  south-america/copa-libertadores
         | 
| 98 | 
            +
             | 
| 99 | 
            +
             | 
| 100 | 
            +
            eg,         africa/egypt
         | 
| 101 | 
            +
            ma,         africa/morocco
         | 
| 102 | 
            +
            dz,         africa/algeria
         | 
| 103 | 
            +
            afl,        africa/african-football-league
         | 
| 104 | 
            +
            caf.cl,     africa/champions-league
         | 
| 105 | 
            +
            caf.champs, africa/champions-league
         | 
| 106 | 
            +
             | 
| 107 | 
            +
             | 
| 108 | 
            +
            cn,  world/asia/china
         | 
| 109 | 
            +
            jp,  world/asia/japan
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            kz,  world/asia/kazakhstan
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            il,  world/middle-east/israel
         | 
| 114 | 
            +
             | 
| 115 | 
            +
             | 
| 116 | 
            +
             | 
| 117 | 
            +
            world,   worldcup
         | 
    
        data/lib/fbup/github.rb
    ADDED
    
    | @@ -0,0 +1,115 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module Fbup
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ###
         | 
| 5 | 
            +
            ## todo/fix:
         | 
| 6 | 
            +
            ##   add -i/--interactive flag
         | 
| 7 | 
            +
            ##     will prompt yes/no  before git operations (with consequences)!!!
         | 
| 8 | 
            +
             | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
            class GitHubSync
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ########
         | 
| 14 | 
            +
            ##  (auto)default to Writer.config.out_dir - why? why not?
         | 
| 15 | 
            +
            ##
         | 
| 16 | 
            +
            ##    note - is monotree (that is, requires openfootball/england etc.
         | 
| 17 | 
            +
            ##                  for repo pathspecs)
         | 
| 18 | 
            +
            def self.root()  @root || "/sports"; end
         | 
| 19 | 
            +
            def self.root=( dir ) @root = dir; end
         | 
| 20 | 
            +
            ## use root_dir (or add alias) - why? why not?
         | 
| 21 | 
            +
             | 
| 22 | 
            +
             | 
| 23 | 
            +
            REPOS = GitHubConfig.new
         | 
| 24 | 
            +
            recs = read_csv( "#{SportDb::Module::Fbup.root}/config/openfootball.csv" )
         | 
| 25 | 
            +
            REPOS.add( recs )
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## note: datasets of format
         | 
| 28 | 
            +
            ##
         | 
| 29 | 
            +
            ## DATASETS = [
         | 
| 30 | 
            +
            ##   ['it.1',    %w[2020/21 2019/20]],
         | 
| 31 | 
            +
            ##  ['it.2',    %w[2019/20]],
         | 
| 32 | 
            +
            ##  ['es.1',    %w[2019/20]],
         | 
| 33 | 
            +
            ##  ['es.2',    %w[2019/20]],
         | 
| 34 | 
            +
            ## ]
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            def self.find_repos( datasets )
         | 
| 37 | 
            +
            repos = []
         | 
| 38 | 
            +
            datasets.each do |league_key, seasons|
         | 
| 39 | 
            +
              repo  = REPOS[ league_key ]
         | 
| 40 | 
            +
              ## pp repo
         | 
| 41 | 
            +
              if repo.nil?
         | 
| 42 | 
            +
                 puts "!! ERROR - no repo config/path found for league >#{league_key}<; sorry"
         | 
| 43 | 
            +
                 exit 1
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              repos <<  "#{repo['owner']}/#{repo['name']}"
         | 
| 47 | 
            +
            end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            pp repos
         | 
| 50 | 
            +
            repos.uniq   ## note: remove duplicates (e.g. europe or world or such)
         | 
| 51 | 
            +
            end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
             | 
| 54 | 
            +
             | 
| 55 | 
            +
            def initialize( repos )
         | 
| 56 | 
            +
                @repos = repos
         | 
| 57 | 
            +
            end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
             | 
| 60 | 
            +
            def git_push_if_changes
         | 
| 61 | 
            +
               message = "auto-update week #{Date.today.cweek}"  ## add /#{Date.today.cday - why? why not?
         | 
| 62 | 
            +
               puts message
         | 
| 63 | 
            +
             | 
| 64 | 
            +
               @repos.each do |pathspec|
         | 
| 65 | 
            +
                   _git_push_if_changes( pathspec, message: message )
         | 
| 66 | 
            +
               end
         | 
| 67 | 
            +
            end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            def git_fast_forward_if_clean
         | 
| 70 | 
            +
                @repos.each do |pathspec|
         | 
| 71 | 
            +
                  _git_fast_forward_if_clean( pathspec )
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
            end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
             | 
| 76 | 
            +
             | 
| 77 | 
            +
            ## todo/fix: rename to something like
         | 
| 78 | 
            +
            ##    git_(auto_)commit_and_push_if_changes/if_dirty()
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            def _git_push_if_changes( pathspec, message: )
         | 
| 81 | 
            +
                path = "#{self.class.root}/#{pathspec}"
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                Gitti::GitProject.open( path ) do |proj|
         | 
| 84 | 
            +
                  puts ''
         | 
| 85 | 
            +
                  puts "###########################################"
         | 
| 86 | 
            +
                  puts "## trying to commit & push repo in path >#{path}<"
         | 
| 87 | 
            +
                  puts "Dir.getwd: #{Dir.getwd}"
         | 
| 88 | 
            +
                  output = proj.changes
         | 
| 89 | 
            +
                  if output.empty?
         | 
| 90 | 
            +
                    puts "no changes found; skipping commit & push"
         | 
| 91 | 
            +
                  else
         | 
| 92 | 
            +
                    proj.add( '.' )
         | 
| 93 | 
            +
                    proj.commit( message )
         | 
| 94 | 
            +
                    proj.push
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
            end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
             | 
| 100 | 
            +
            def _git_fast_forward_if_clean( pathspec )
         | 
| 101 | 
            +
                path = "#{self.class.root}/#{pathspec}"
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                Gitti::GitProject.open( path ) do |proj|
         | 
| 104 | 
            +
                  output = proj.changes
         | 
| 105 | 
            +
                  unless  output.empty?
         | 
| 106 | 
            +
                    puts "FAIL - cannot git pull (fast-forward) - working tree has changes:"
         | 
| 107 | 
            +
                    puts output
         | 
| 108 | 
            +
                    exit 1
         | 
| 109 | 
            +
                  end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  proj.fast_forward
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
            end
         | 
| 114 | 
            +
            end  # class GitHub
         | 
| 115 | 
            +
            end  # module Fbup
         | 
| @@ -0,0 +1,97 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module Fbup
         | 
| 3 | 
            +
            class GitHubConfig
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              ## map leagues to repo+path
         | 
| 6 | 
            +
              ##  e.g.   fr.1   => europe/france
         | 
| 7 | 
            +
              ##         eng..1 => england
         | 
| 8 | 
            +
              ##
         | 
| 9 | 
            +
              ##  for other than openfootball (default)
         | 
| 10 | 
            +
              ## use @
         | 
| 11 | 
            +
              ##   e.g.    myorg@austria
         | 
| 12 | 
            +
              ##           austria@myorg ??
         | 
| 13 | 
            +
              ##
         | 
| 14 | 
            +
              ##           myorg@europe/france
         | 
| 15 | 
            +
              ##            europe/france@myorg
         | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 18 | 
            +
            def self.read( path )
         | 
| 19 | 
            +
                recs = read_csv( path )
         | 
| 20 | 
            +
                new( recs )
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            def initialize( recs=nil )
         | 
| 24 | 
            +
                @table = {}
         | 
| 25 | 
            +
                add( recs )  if recs
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
             | 
| 29 | 
            +
            def add( recs )
         | 
| 30 | 
            +
              recs.each do |rec|
         | 
| 31 | 
            +
                path = rec['path']  ## use pathspec - why? why not?
         | 
| 32 | 
            +
                                    ##  or repospec or such
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                ## auto-expand to openfootball as default org if no @ specified
         | 
| 35 | 
            +
                owner, path = if path.index( '@')
         | 
| 36 | 
            +
                                  path.split( '@', 2 )
         | 
| 37 | 
            +
                              else
         | 
| 38 | 
            +
                                  ['openfootball', path ]
         | 
| 39 | 
            +
                              end
         | 
| 40 | 
            +
                name, path = path.split( '/', 2 )
         | 
| 41 | 
            +
             | 
| 42 | 
            +
             | 
| 43 | 
            +
                ## openfootball@europe/france
         | 
| 44 | 
            +
                ##    =>
         | 
| 45 | 
            +
                ##    owner: openfootball
         | 
| 46 | 
            +
                ##    name:  europe
         | 
| 47 | 
            +
                ##    path:  france
         | 
| 48 | 
            +
                ##
         | 
| 49 | 
            +
                ## openfootball@austria
         | 
| 50 | 
            +
                ##    =>
         | 
| 51 | 
            +
                ##    owner: openfootball
         | 
| 52 | 
            +
                ##    name:  austria
         | 
| 53 | 
            +
                ##    path:  nil
         | 
| 54 | 
            +
                @table[ rec['key'] ] = {  'owner' => owner, ## (required)
         | 
| 55 | 
            +
                                          'name'  => name,  ## (required)
         | 
| 56 | 
            +
                                          'path'  => path   ## extra/inner/inside/local path (optional)
         | 
| 57 | 
            +
                                        }
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
             | 
| 62 | 
            +
            ##
         | 
| 63 | 
            +
            ## todo/fix:
         | 
| 64 | 
            +
            ##   make key lookup more flexible
         | 
| 65 | 
            +
            ##    auto-add more variants!!!
         | 
| 66 | 
            +
            ##       e.g. at.1  AT1, AT or such
         | 
| 67 | 
            +
            ##
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            ## find (full) record by key
         | 
| 70 | 
            +
            def find( key )
         | 
| 71 | 
            +
              key = key.to_s.downcase
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              ## first check for 1:1 match
         | 
| 74 | 
            +
              rec = @table[key]
         | 
| 75 | 
            +
              if rec.nil?
         | 
| 76 | 
            +
                 ## try match by (country / first) code
         | 
| 77 | 
            +
                 ##   split by .
         | 
| 78 | 
            +
                 key, _ = key.split( '.' )
         | 
| 79 | 
            +
                 rec = @table[key]
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              rec
         | 
| 83 | 
            +
            end
         | 
| 84 | 
            +
            alias_method :[], :find  ## keep alias - why? why not?
         | 
| 85 | 
            +
             | 
| 86 | 
            +
             | 
| 87 | 
            +
            def find_repo( key )
         | 
| 88 | 
            +
               rec = _find( key )
         | 
| 89 | 
            +
             | 
| 90 | 
            +
               rec ? "#{rec['owner']}/#{rec['name']}" : nil
         | 
| 91 | 
            +
            end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
            end # class GitHubConfig
         | 
| 94 | 
            +
            end # module Fbup
         | 
| 95 | 
            +
             | 
| 96 | 
            +
             | 
| 97 | 
            +
             | 
    
        data/lib/fbup/main.rb
    ADDED
    
    | @@ -0,0 +1,165 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module Fbup
         | 
| 3 | 
            +
            def self.main( args=ARGV )
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            opts = {
         | 
| 6 | 
            +
              source_path: [],
         | 
| 7 | 
            +
              push:     false,
         | 
| 8 | 
            +
              ffwd:     false,
         | 
| 9 | 
            +
              dry:      false,  ## dry run (no write)
         | 
| 10 | 
            +
              test:     true,   ## sets push & ffwd to false
         | 
| 11 | 
            +
              debug:    true,
         | 
| 12 | 
            +
              file:     nil,
         | 
| 13 | 
            +
              test_dir:  './o',
         | 
| 14 | 
            +
            }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
             | 
| 17 | 
            +
            parser = OptionParser.new do |parser|
         | 
| 18 | 
            +
              parser.banner = "Usage: #{$PROGRAM_NAME} [options] [args]"
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                parser.on( "-p", "--[no-]push",
         | 
| 21 | 
            +
                           "fast forward sync and commit & push changes to git repo - default is (#{opts[:push]})" ) do |push|
         | 
| 22 | 
            +
                  opts[:push] = push
         | 
| 23 | 
            +
                  if opts[:push]   ## note: autoset ffwd too if push == true
         | 
| 24 | 
            +
                    opts[:ffwd] = true
         | 
| 25 | 
            +
                    opts[:test] = false
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
                ## todo/check - add a --ffwd flag too - why? why not?
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                parser.on( "-t", "--test",
         | 
| 31 | 
            +
                            "test run; writing output to #{opts[:test_dir]} - default is #{opts[:test]}" ) do |test|
         | 
| 32 | 
            +
                  opts[:test] = true
         | 
| 33 | 
            +
                  opts[:push] = false
         | 
| 34 | 
            +
                  opts[:ffwd] = false
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                parser.on( "--dry",
         | 
| 38 | 
            +
                            "dry run; do NOT write - default is (#{opts[:dry]})" ) do |dry|
         | 
| 39 | 
            +
                  opts[:dry] = dry
         | 
| 40 | 
            +
                  opts[:test] = false
         | 
| 41 | 
            +
                  opts[:push] = false    ### autoset push & ffwd - why? why not?
         | 
| 42 | 
            +
                  opts[:ffwd] = false
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                parser.on( "-q", "--quiet",
         | 
| 46 | 
            +
                           "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
         | 
| 47 | 
            +
                  opts[:debug] = false
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                parser.on( "-I DIR", "--include DIR",
         | 
| 51 | 
            +
                            "add directory to (source) search path - default is (#{opts[:source_path].join(',')})") do |dir|
         | 
| 52 | 
            +
                  opts[:source_path] += path
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                parser.on( "-f FILE", "--file FILE",
         | 
| 56 | 
            +
                            "read leagues (and seasons) via .csv file") do |file|
         | 
| 57 | 
            +
                  opts[:file] = file
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
            parser.parse!( args )
         | 
| 61 | 
            +
             | 
| 62 | 
            +
             | 
| 63 | 
            +
            if opts[:source_path].empty? &&
         | 
| 64 | 
            +
               File.exist?( '/sports/cache.api.fbdat')  &&
         | 
| 65 | 
            +
               File.exist?( '/sports/cache.wfb' )
         | 
| 66 | 
            +
                 opts[:source_path] << '/sports/cache.api.fbdat'
         | 
| 67 | 
            +
                 opts[:source_path] << '/sports/cache.wfb'
         | 
| 68 | 
            +
            end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            if opts[:source_path].empty?
         | 
| 71 | 
            +
              opts[:source_path]  = ['.']   ## use ./ as default
         | 
| 72 | 
            +
            end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
             | 
| 75 | 
            +
             | 
| 76 | 
            +
            puts "OPTS:"
         | 
| 77 | 
            +
            p opts
         | 
| 78 | 
            +
            puts "ARGV:"
         | 
| 79 | 
            +
            p args
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             | 
| 82 | 
            +
            datasets =   if opts[:file]
         | 
| 83 | 
            +
                              read_leagueset( opts[:file] )
         | 
| 84 | 
            +
                         else
         | 
| 85 | 
            +
                              parse_leagueset_args( args )
         | 
| 86 | 
            +
                         end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            puts "datasets:"
         | 
| 89 | 
            +
            pp datasets
         | 
| 90 | 
            +
             | 
| 91 | 
            +
             | 
| 92 | 
            +
            source_path = opts[:source_path]
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            root_dir =  if opts[:test]
         | 
| 95 | 
            +
                           opts[:test_dir]
         | 
| 96 | 
            +
                        else
         | 
| 97 | 
            +
                           GitHubSync.root   # e.g. "/sports"
         | 
| 98 | 
            +
                        end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            puts "  (output) root_dir: >#{root_dir}<"
         | 
| 101 | 
            +
             | 
| 102 | 
            +
            repos = GitHubSync.find_repos( datasets )
         | 
| 103 | 
            +
            puts "  #{repos.size} repo(s):"
         | 
| 104 | 
            +
            pp repos
         | 
| 105 | 
            +
            sync  =  GitHubSync.new( repos )
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            puts "  sync:"
         | 
| 108 | 
            +
            pp sync
         | 
| 109 | 
            +
             | 
| 110 | 
            +
             | 
| 111 | 
            +
             | 
| 112 | 
            +
            sync.git_fast_forward_if_clean    if opts[:ffwd]
         | 
| 113 | 
            +
             | 
| 114 | 
            +
            ### step 0 - validate and fill-in seasons etc.
         | 
| 115 | 
            +
            datasets.validate!( source_path: source_path )
         | 
| 116 | 
            +
             | 
| 117 | 
            +
             | 
| 118 | 
            +
             | 
| 119 | 
            +
            datasets.each do |league_key, seasons|
         | 
| 120 | 
            +
                puts "==> gen #{league_key} - #{seasons.size} seasons(s)..."
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                league_info = find_league_info( league_key )
         | 
| 123 | 
            +
                pp league_info
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                seasons.each do |season|
         | 
| 126 | 
            +
                  filename = "#{season.to_path}/#{league_key}.csv"
         | 
| 127 | 
            +
                  path = find_file( filename, path: source_path )
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                  ### get matches
         | 
| 130 | 
            +
                  puts "  ---> reading matches in #{path} ..."
         | 
| 131 | 
            +
                  matches = SportDb::CsvMatchParser.read( path )
         | 
| 132 | 
            +
                  puts "     #{matches.size} matches"
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                  ## build
         | 
| 135 | 
            +
                  txt = SportDb::TxtMatchWriter.build( matches )
         | 
| 136 | 
            +
                  puts txt   if opts[:debug]
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                  league_name  = league_info[ :name ]      # e.g. Brasileiro Série A
         | 
| 139 | 
            +
                  basename     = league_info[ :basename]   #.e.g  1-seriea
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                  league_name =  league_name.call( season )   if league_name.is_a?( Proc )  ## is proc/func - name depends on season
         | 
| 142 | 
            +
                  basename    =  basename.call( season )      if basename.is_a?( Proc )  ## is proc/func - name depends on season
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                  buf = String.new
         | 
| 145 | 
            +
                  buf << "= #{league_name} #{season}\n\n"
         | 
| 146 | 
            +
                  buf << txt
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                  repo  = GitHubSync::REPOS[ league_key ]
         | 
| 149 | 
            +
                  repo_path = "#{repo['owner']}/#{repo['name']}"
         | 
| 150 | 
            +
                  repo_path << "/#{repo['path']}"    if repo['path']  ## note: do NOT forget to add optional extra path!!!
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                  outpath = "#{root_dir}/#{repo_path}/#{season.to_path}/#{basename}.txt"
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                  if opts[:dry]
         | 
| 155 | 
            +
                    puts "   (dry) writing to >#{outpath}<..."
         | 
| 156 | 
            +
                  else
         | 
| 157 | 
            +
                    write_text( outpath, buf )
         | 
| 158 | 
            +
                  end
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
            end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
            sync.git_push_if_changes   if opts[:push]
         | 
| 163 | 
            +
             | 
| 164 | 
            +
            end  # method self.main
         | 
| 165 | 
            +
            end  # module Fbup
         | 
    
        data/lib/fbup/version.rb
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module SportDb
         | 
| 3 | 
            +
            module Module
         | 
| 4 | 
            +
              module Fbup
         | 
| 5 | 
            +
                MAJOR = 0    ## todo: namespace inside version or something - why? why not??
         | 
| 6 | 
            +
                MINOR = 0
         | 
| 7 | 
            +
                PATCH = 1
         | 
| 8 | 
            +
                VERSION = [MAJOR,MINOR,PATCH].join('.')
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def self.version
         | 
| 11 | 
            +
                  VERSION
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def self.banner
         | 
| 15 | 
            +
                  "fbup/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def self.root
         | 
| 19 | 
            +
                  File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              end # module Fbup
         | 
| 23 | 
            +
            end # module Module
         | 
| 24 | 
            +
            end # module SportDb
         | 
    
        data/lib/fbup.rb
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'sportdb/writers'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'optparse'    ## command-line processing; check if included updstream?
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ########################
         | 
| 8 | 
            +
            #  push & pull github scripts
         | 
| 9 | 
            +
            require 'gitti'    ## note - requires git machinery
         | 
| 10 | 
            +
             | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            ###
         | 
| 14 | 
            +
            # our own code
         | 
| 15 | 
            +
            require_relative 'fbup/version'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            require_relative 'fbup/github_config'
         | 
| 18 | 
            +
            require_relative 'fbup/github'   ## github helpers/update machinery
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
            require_relative 'fbup/main'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
             | 
| 24 | 
            +
             | 
| 25 | 
            +
             | 
| 26 | 
            +
             | 
| 27 | 
            +
            puts SportDb::Module::Fbup.banner   # say hello
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,124 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: fbup
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Gerald Bauer
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2024-12-29 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: sportdb-writers
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 0.4.0
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 0.4.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: gitti
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 0.6.1
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 0.6.1
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rdoc
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '4.0'
         | 
| 48 | 
            +
                - - "<"
         | 
| 49 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 50 | 
            +
                    version: '7'
         | 
| 51 | 
            +
              type: :development
         | 
| 52 | 
            +
              prerelease: false
         | 
| 53 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 54 | 
            +
                requirements:
         | 
| 55 | 
            +
                - - ">="
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 57 | 
            +
                    version: '4.0'
         | 
| 58 | 
            +
                - - "<"
         | 
| 59 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                    version: '7'
         | 
| 61 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 62 | 
            +
              name: hoe
         | 
| 63 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 64 | 
            +
                requirements:
         | 
| 65 | 
            +
                - - "~>"
         | 
| 66 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 67 | 
            +
                    version: '4.2'
         | 
| 68 | 
            +
              type: :development
         | 
| 69 | 
            +
              prerelease: false
         | 
| 70 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
                requirements:
         | 
| 72 | 
            +
                - - "~>"
         | 
| 73 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 74 | 
            +
                    version: '4.2'
         | 
| 75 | 
            +
            description: fbup - (auto-)update machinery for footbal match schedules & more in
         | 
| 76 | 
            +
              football.txt; incl. (auto-sync & commit) support for github openfootball repos &
         | 
| 77 | 
            +
              more
         | 
| 78 | 
            +
            email: gerald.bauer@gmail.com
         | 
| 79 | 
            +
            executables:
         | 
| 80 | 
            +
            - fbup
         | 
| 81 | 
            +
            extensions: []
         | 
| 82 | 
            +
            extra_rdoc_files:
         | 
| 83 | 
            +
            - CHANGELOG.md
         | 
| 84 | 
            +
            - Manifest.txt
         | 
| 85 | 
            +
            - README.md
         | 
| 86 | 
            +
            files:
         | 
| 87 | 
            +
            - CHANGELOG.md
         | 
| 88 | 
            +
            - Manifest.txt
         | 
| 89 | 
            +
            - README.md
         | 
| 90 | 
            +
            - Rakefile
         | 
| 91 | 
            +
            - bin/fbup
         | 
| 92 | 
            +
            - config/openfootball.csv
         | 
| 93 | 
            +
            - lib/fbup.rb
         | 
| 94 | 
            +
            - lib/fbup/github.rb
         | 
| 95 | 
            +
            - lib/fbup/github_config.rb
         | 
| 96 | 
            +
            - lib/fbup/main.rb
         | 
| 97 | 
            +
            - lib/fbup/version.rb
         | 
| 98 | 
            +
            homepage: https://github.com/sportdb/sport.db
         | 
| 99 | 
            +
            licenses:
         | 
| 100 | 
            +
            - Public Domain
         | 
| 101 | 
            +
            metadata: {}
         | 
| 102 | 
            +
            post_install_message:
         | 
| 103 | 
            +
            rdoc_options:
         | 
| 104 | 
            +
            - "--main"
         | 
| 105 | 
            +
            - README.md
         | 
| 106 | 
            +
            require_paths:
         | 
| 107 | 
            +
            - lib
         | 
| 108 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 109 | 
            +
              requirements:
         | 
| 110 | 
            +
              - - ">="
         | 
| 111 | 
            +
                - !ruby/object:Gem::Version
         | 
| 112 | 
            +
                  version: 3.1.0
         | 
| 113 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
              requirements:
         | 
| 115 | 
            +
              - - ">="
         | 
| 116 | 
            +
                - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                  version: '0'
         | 
| 118 | 
            +
            requirements: []
         | 
| 119 | 
            +
            rubygems_version: 3.5.22
         | 
| 120 | 
            +
            signing_key:
         | 
| 121 | 
            +
            specification_version: 4
         | 
| 122 | 
            +
            summary: fbup - (auto-)update machinery for footbal match schedules & more in football.txt;
         | 
| 123 | 
            +
              incl. (auto-sync & commit) support for github openfootball repos & more
         | 
| 124 | 
            +
            test_files: []
         |