Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
104 lines (92 sloc) 4.73 KB
import os
import shutil
from urllib.parse import urlparse
import urllib.request
from helpers.coreutil import *
import subprocess
import re
import zipfile
import io
class Validator(object):
def validate_url(url):
# This is taken from Stack Overflow:
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
r'localhost|' #localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
return re.match(regex, url) is not None
class LibraryInstaller(object):
def install_python_library(library):
process_result =['pip3', 'install', '-t', 'dtemp/packages', library], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
class PresenceVerifier(object):
def docfx_exists(auto_install):
if (os.path.exists('dbin/docfx/docfx.exe')):
return True
if auto_install:
print('Donwloading and extracting DocFX...')
urllib.request.urlretrieve("", "")
with zipfile.ZipFile("", "r") as zip_ref:
return True
return False
def shell_command_exists(command):
return shutil.which(command) is not None
class LibraryProcessor(object):
def process_libraries(libraries, platform, docpath):
if (platform.lower() == 'python'):
if (PresenceVerifier.shell_command_exists('pip3')):
for library in libraries:
if (Validator.validate_url(library)):
url_parse_result = urlparse(library)
domain = url_parse_result.netloc
if (domain.lower().endswith("")):
print (f'[info] Getting {library} from GitHub...')
print (f'[info] Getting {library} from a direct source...')
print ('[error] Could not install library from source.')
# Not a URL, so we should try taking this as a PyPI package.
print (f'[info] The {library} is not a direct pointer - attempting to read from PyPI.')
# TODO: Need to implement a check that verifies whether the library was really installed.
LibraryDocumenter.document_python_library(library, docpath)
print ('[error] Could not find an installed pip3 tool. Make sure that Python tooling is installed if you are documenting Python packages.')
class LibraryDocumenter(object):
def document_python_library(library, docpath):
true_docpath = docpath
if not docpath:
process_result =['mono', 'dbin/docfx/docfx.exe', 'init', '-q', '-o', 'dsite'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
true_docpath = "dsite/api"
process_result =['pip3', 'list',], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if 'spinx-docfx-yaml' in process_result.stdout.decode('utf-8'):
# We have the extension ( installed
print ('[info] The sphinx-docfx-yaml extension is already installed.')
print ('[info] Installing sphinx-docfx-yaml...')
process_result =['pip3', 'install', 'sphinx-docfx-yaml', '--user'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print (f'[info] Processing documentation for {library}...')
process_result =['sh', 'scripts/', 'dtemp/packages', library.replace('-','/'), os.path.abspath(true_docpath)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
class ConsoleUtil(object):
def pretty_stdout(stdout):
output = str(stdout)
output = output.split('\\n')
for x in range(len(output)):
print (output[x])
You can’t perform that action at this time.