Skip to content

Commit bcfd981

Browse files
committed
.
1 parent e189727 commit bcfd981

2 files changed

Lines changed: 34 additions & 52 deletions

File tree

nbgitpuller/config.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

nbgitpuller/pull.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import time
66
import argparse
77
import datetime
8-
from traitlets import Integer, default
8+
from traitlets import Bool, CRegExp, Integer, List, Unicode, Union, default
99
from traitlets.config import Configurable
1010
from functools import partial
1111

12-
from config import NbGitPullerFeatures
1312

1413
def execute_cmd(cmd, **kwargs):
1514
"""
@@ -51,6 +50,35 @@ def flush():
5150

5251

5352
class GitPuller(Configurable):
53+
autorun_allow = Union(
54+
[List(CRegExp()), Bool()],
55+
default_value=False,
56+
config=True,
57+
help="""
58+
List of URLs described as Python regular expressions (using re.match()) where we
59+
allow autorunning scripts in the pulled project as a pre-initialisation step.
60+
Enable this only if you understand and accept the risks of AUTORUN.INF.
61+
62+
When set to boolean True, all URLs are allowed, whilst False (default) autorun
63+
is disable completely.
64+
"""
65+
)
66+
67+
autorun_script = List(
68+
Unicode(),
69+
default_value=[],
70+
config=True,
71+
help="""
72+
List of scripts to search for when attempting to autorun. The first match will
73+
be run with a single argument of 'init' or 'update' depending on what nbgitpuller
74+
is doing.
75+
76+
Only used if autorun_allow is changed from its default of False.
77+
78+
Enable this only if you understand and accept the risks of AUTORUN.INF.
79+
"""
80+
)
81+
5482
depth = Integer(
5583
config=True,
5684
help="""
@@ -82,19 +110,6 @@ def __init__(self, git_url, repo_dir, **kwargs):
82110
elif not self.branch_exists(self.branch_name):
83111
raise ValueError(f"Branch: {self.branch_name} -- not found in repo: {self.git_url}")
84112

85-
features = NbGitPullerFeatures(parent=kwargs.get("parent"))
86-
if features.autorun_allow is True:
87-
self._autorun = True
88-
elif isinstance(features.autorun_allow, list):
89-
self._autorun = any(( re.match(pattern, git_url) for pattern in features.autorun_allow ))
90-
else:
91-
self._autorun = False
92-
if self._autorun:
93-
if isinstance(features.autorun_script, list):
94-
self._autorun_script = features.autorun_script
95-
else:
96-
self._autorun = False
97-
98113
self.repo_dir = repo_dir
99114
newargs = {k: v for k, v in kwargs.items() if v is not None}
100115
super(GitPuller, self).__init__(**newargs)
@@ -162,7 +177,10 @@ def autorun(self, operation="method"):
162177
"""
163178
Search for and execute the autorun script.
164179
"""
165-
if not self._autorun:
180+
181+
if not self.autorun_allow:
182+
return
183+
if not any(( re.match(pattern, self.git_url) for pattern in self.autorun_allow )):
166184
return
167185

168186
script = next(( s for s in self._autorun_script if os.path.exists(os.path.join(self.repo_dir, s)) ), None)

0 commit comments

Comments
 (0)