2017-09-06 8 views
0

나는 gitlab에 투입 바이너리 파일을 무시하도록 후크를 추가하려고, 그래서 /opt/gitlab/embedded/service/gitlab-shell/lib의 새로운 파이썬 (평) 후크를 추가하고 난 /opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.rbruby ​​hook에서 python 파일을로드하는 방법은 무엇입니까?

에서 해당 파일을로드하지만 파일을 커밋했을 때 내가 아래 예외의 화면을

원격 커밋되었다 : 후크/선주문 수신 : 17 :

'require_relative': cannot load such file -- /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_ignore_binary.py (LoadError) remote: from hooks/pre-receive:17:in 내 미리 수신 후크 파일

이다
#!/opt/gitlab/embedded/bin/ruby 
    # Fix the PATH so that gitlab-shell can find git-upload-pack and friends. 
    ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH'] 

    #!/usr/bin/env ruby 
    #!/usr/bin/env python 

# This file was placed here by GitLab. It makes sure that your pushed commits 
# will be processed properly. 

refs = $stdin.read 
key_id = ENV.delete('GL_ID') 
protocol = ENV.delete('GL_PROTOCOL') 
repo_path = Dir.pwd 
gl_repository = ENV['GL_REPOSITORY'] 

require_relative '../lib/gitlab_ignore_binary.py' 
require_relative '../lib/gitlab_custom_hook' 
require_relative '../lib/gitlab_reference_counter' 
require_relative '../lib/gitlab_access' 


# It's important that on pre-receive `increase_reference_counter` gets executed 
# last so that it only runs if everything else succeeded. On post-receive on the 
# other hand, we run GitlabPostReceive first because the push is already done 
# and we don't want to skip it if the custom hook fails. 
if GitlabAccess.new(gl_repository, repo_path, key_id, refs, protocol).exec && 
    GitlabCustomHook.new(repo_path, key_id).pre_receive(refs) && 
    GitlabReferenceCounter.new(repo_path).increase 

    exit 0 
else 
    exit 1 
end 

.py 파일을로드 할 수없는 이유는 무엇입니까?

답변

0

Kernel#require에서이 기본 조각은 아마 당신을 위해 그것을 요약한다 : 파일 이름이 확장자가 ".rb"가

의 경우는 소스 파일로로드; 확장자가 ".so", ".o"또는 ".dll"이거나 현재 플랫폼의 기본 공유 라이브러리 확장 인 경우 Ruby는 공유 라이브러리를 Ruby 확장으로로드합니다. 그렇지 않으면 Ruby는 찾을 때까지 ".rb", ".so"등을 이름에 추가하려고합니다. 명명 된 파일을 찾을 수 없으면 LoadError가 발생합니다.

사이드 너에서 어떻게 이것이 행동 할 것으로 예상 했습니까? 루비 인터프리터는 어떻게 파이썬 파일을 처리해야합니까?

+0

나는 후크를 작성하려고 했으므로 파이썬으로 시도했다. 이제 루비 코드를 변경해야한다. 무엇을해야합니까? –