scrapy / scrapy
1 7
import sys
2 7
import os
3

4 7
from scrapy.commands import ScrapyCommand
5 7
from scrapy.exceptions import UsageError
6

7

8 7
class Command(ScrapyCommand):
9

10 7
    requires_project = True
11 7
    default_settings = {'LOG_ENABLED': False}
12

13 7
    def syntax(self):
14 0
        return "<spider>"
15

16 7
    def short_desc(self):
17 0
        return "Edit spider"
18

19 7
    def long_desc(self):
20 0
        return ("Edit a spider using the editor defined in the EDITOR environment"
21
                " variable or else the EDITOR setting")
22

23 7
    def _err(self, msg):
24 0
        sys.stderr.write(msg + os.linesep)
25 0
        self.exitcode = 1
26

27 7
    def run(self, args, opts):
28 7
        if len(args) != 1:
29 0
            raise UsageError()
30

31 0
        editor = self.settings['EDITOR']
32 0
        try:
33 0
            spidercls = self.crawler_process.spider_loader.load(args[0])
34 0
        except KeyError:
35 0
            return self._err(f"Spider not found: {args[0]}")
36

37 0
        sfile = sys.modules[spidercls.__module__].__file__
38 0
        sfile = sfile.replace('.pyc', '.py')
39 0
        self.exitcode = os.system(f'{editor} "{sfile}"')

Read our documentation on viewing source code .

Loading