File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import logging
55import click
66
77from kt .commands .list_kernels .command import list_kernels
8+ from kt .commands .setup .command import setup
89
910epilog = """
1011Base of all tooling used for kernel development.
@@ -22,6 +23,7 @@ def main():
2223 logging .basicConfig (format = "%(levelname)s:%(message)s" , level = logging .INFO )
2324
2425 cli .add_command (list_kernels )
26+ cli .add_command (setup )
2527 cli ()
2628
2729
Original file line number Diff line number Diff line change @@ -145,3 +145,30 @@ lts-8.8
145145lts-9.2
146146lts-9.4
147147```
148+
149+ ### kt setup
150+
151+ ```
152+ $ kt setup --help
153+ ```
154+
155+ It prepares the working directory for later commands:
156+
157+ It clones the common_repos from kernels.yaml file in the config.base_path
158+ directory.
159+ If config.base_path = ~ /ciq, these will be created:
160+
161+ ~ /ciq/kernel-src-tree
162+
163+ ~ /ciq/dist-git-tree-fips
164+
165+ ~ /ciq/dist-git-tree-cbr
166+
167+ ~ /ciq/dit-git-tree-lts
168+
169+ ~ /ciq/kernel-src-tree-tools
170+
171+ ~ /ciq/kernel-tools
172+
173+ If there's a repo that needs to be cloned relevant for any future command,
174+ this is when it should be cloned.
Original file line number Diff line number Diff line change 1+ import click
2+
3+ from kt .commands .setup .impl import main
4+
5+ epilog = """
6+ Prepares the working directory for later commands:
7+
8+ It clones the common_repos from kernels.yaml file in the config.base_path
9+ directory.
10+ If the repos are cloned already, they will be updated.
11+
12+ If config.base_path = ~/ciq, these will be created:
13+
14+ ~/ciq/kernel-src-tree
15+
16+ ~/ciq/dist-git-tree-fips
17+
18+ ~/ciq/dist-git-tree-cbr
19+
20+ ~/ciq/dit-git-tree-lts
21+
22+ ~/ciq/kernel-src-tree-tools
23+
24+ ~/ciq/kernel-tools
25+
26+ Examples:
27+
28+ \b
29+ $ kt setup
30+ """
31+
32+
33+ @click .command (epilog = epilog )
34+ def setup ():
35+ main ()
Original file line number Diff line number Diff line change 1+ from kt .ktlib .config import Config
2+ from kt .ktlib .kernels import KernelsInfo
3+
4+
5+ def main ():
6+ config = Config .load ()
7+
8+ # create working dir if it does not exist
9+ config .base_path .mkdir (parents = True , exist_ok = True )
10+
11+ repos = KernelsInfo .from_yaml (config = config ).repos
12+ for repo in repos .values ():
13+ repo .setup_repo ()
Original file line number Diff line number Diff line change 55from pathlib3x import Path
66
77from kt .ktlib .config import Config
8+ from kt .ktlib .repo import RepoInfo
89from kt .ktlib .util import Constants
910
1011# TODO move this to a separate repo
1112KERNEL_INFO_YAML_PATH = Path (__file__ ).parent .parent .joinpath ("data/kernels.yaml" )
1213
1314
14- @dataclass
15- class RepoInfo :
16- """
17- Dataclass that represents a local clone of a git repository.
18- folder: absolute path to the local clone
19- url: remote origin
20- """
21-
22- folder : Path
23- url : str
24-
25-
2615@dataclass
2716class KernelInfo :
2817 """
Original file line number Diff line number Diff line change 1+ import logging
2+ from dataclasses import dataclass
3+
4+ import git
5+ from git import Repo
6+ from pathlib3x import Path
7+
8+
9+ @dataclass
10+ class RepoInfo :
11+ """
12+ Dataclass that represents a local clone of a git repository.
13+ folder: absolute path to the local clone
14+ url: remote origin
15+ """
16+
17+ folder : Path
18+ url : str
19+
20+ def _clone_repo (self ):
21+ """
22+ It clones the repo into destination folder
23+ """
24+
25+ # TODO show progress
26+ logging .info (f"Cloning { self .url } to { self .folder } " )
27+ git .Repo .clone_from (self .url , self .folder )
28+
29+ def _update (self ):
30+ repo = Repo (self .folder )
31+ repo .remotes .origin .pull (rebase = True )
32+
33+ def setup_repo (self ):
34+ """
35+ Set up a git repository at the destination.
36+ If destination already exists and override == True,
37+ nothing is done
38+ """
39+ if not self .folder .exists ():
40+ self ._clone_repo ()
41+ return
42+
43+ logging .info (f"{ self .folder } already exists, updating it" )
44+ self ._update ()
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ readme = "README.md"
77version = " 0.0.1"
88dependencies = [
99 " click" ,
10+ " gitpython" ,
1011 " pathlib3x" ,
1112]
1213
You can’t perform that action at this time.
0 commit comments