# Path: winbrew/manifest.py
# class Manifest:
#     """
#     Stores a list of all files installed by a formula.  This class is used to
#     determine which files to uninstall, and to check for conflicts between
#     formulas.
#     """
# 
#     def __init__(self, name):
#         self.files = []
#         self.name = name
#         self.status = 'uninstalled'
# 
#     def save(self):
#         """
#         Write the manifest to the manifest file directory
#         """
#         values = [(path, self.name) for path in self.files]
#         query = 'REPLACE INTO InstalledFile (path, formula) VALUES (?, ?)'
#         self.db().cursor().executemany(query, values)
# 
#         query = 'REPLACE INTO Formula (name, status) VALUES (?, ?)'
#         self.db().cursor().execute(query, (self.name, self.status))
# 
#         self.db().commit()
# 
#     def load(self):
#         """
#         Read the manifest from the manifest file directory
#         """
#         query = 'SELECT path FROM InstalledFile WHERE formula=?'
#         results = self.db().cursor().execute(query, (self.name,))
#         self.files = [result[0] for result in results]
# 
#         query = 'SELECT status FROM Formula where name=?'
#         results = self.db().cursor().execute(query, (self.name,))
#         try:
#             self.status = next(results)[0]
#         except StopIteration:
#             pass
# 
#     def delete(self):
#         """
#         Delete the manifest
#         """
#         query = 'DELETE FROM InstalledFile WHERE formula=?'
#         self.db().cursor().execute(query, (self.name,))
#         query = 'DELETE FROM Formula WHERE name=?'
#         self.db().cursor().execute(query, (self.name,))
#         self.db().commit()
# 
#     @property
#     def installed(self):
#         """
#         Returns true if the Manifest indicates the formula is installed
#         """
#         return self.status == 'installed'
# 
#     @classmethod
#     def all(self):
#         """
#         List all installed packages
#         """
#         query = 'SELECT DISTINCT formula FROM InstalledFile'
#         results = self.db().cursor().execute(query)
#         return [Manifest(result[0]) for result in results]
#         # FIXME: This may be inefficient
# 
#     @classmethod
#     def db(self):
#         if not getattr(self, '_db', None):
#             winbrew.util.mkdir_p(winbrew.manifest_path)
#             self._db = sqlite3.connect(os.path.join(winbrew.manifest_path, 'manifest.db'))
#             self.migrate()
#         return self._db
# 
#     @classmethod
#     def migrate(self):
#         """
#         Execute database migrations
#         """
#         self._db.cursor().execute("""
#         CREATE TABLE IF NOT EXISTS InstalledFile (
#             path TEXT NOT NULL UNIQUE,
#             formula TEXT NOT NULL,
#             PRIMARY KEY(path, formula)
#         )
#         """)
# 
#         self._db.cursor().execute("""
#         CREATE TABLE IF NOT EXISTS Formula (
#             name TEXT NOT NULL UNIQUE,
#             status TEXT NOT NULL,
#             PRIMARY KEY(name)
#         )
#         """)
# 
# Path: winbrew/archive.py
# class Archive:
#     """
#     Archive describes the type of package to download. Typically, some kind of
#     compressed file (tar, zip) or a git repository.
#     """
# 
#     @staticmethod
#     def create(url, work_dir, package_name):
#         ext = os.path.splitext(url)[1]
#         name = os.path.split(url)[1]
# 
#         if ext == '.zip':
#             return ZipArchive(url, work_dir, name)
#         elif ext == '.gz':
#             return TarArchive(url, work_dir, name, compression='gz')
#         elif ext == '.tgz':
#             return TarArchive(url, work_dir, name, compression='gz')
#         elif ext == '.bz2':
#             return TarArchive(url, work_dir, name, compression='bz2')
#         elif ext == '.xz':
#             return TarArchive(url, work_dir, name, compression='xz')
#         elif ext == '.msi':
#             return MsiArchive(url, work_dir, name)
#         elif ext == '.git':
#             return GitArchive(url, work_dir, package_name)
#         else:
#             raise Exception('unknown archive file type')
# 
#     def __init__(self, url, work_dir, name):
#         self.url = url
# 
#         # Parent working directory in cache
#         self.work_dir = work_dir
# 
#         # File name
#         self.name = name
# 
#         # Full downloaded file path
#         self.path = os.path.join(work_dir, name)
# 
#     def download(self):
#         winbrew.util.rm_rf(self.work_dir)
#         winbrew.util.mkdir_p(self.work_dir)
# 
#         with open(self.path, 'wb') as fd, self.urlopen() as stream:
#             shutil.copyfileobj(stream, fd)
# 
#     def urlopen(self):
#         headers = {
#             'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'
#         }
# 
#         request = urllib.request.Request(self.url, headers=headers)
#         return urllib.request.urlopen(request)
# 
#     def clean(self):
#         for fn in os.listdir(self.work_dir):
#             if fn != self.name:
#                 winbrew.util.rm_rf(os.path.join(self.work_dir, fn))
#     @property
#     def unpack_dir(self):
#         return os.path.join(self.work_dir, self.unpack_name)


import subprocess
import sys
import os
import errno
import glob
import shutil
import shlex
import imp
import winbrew
import argparse
import hashlib
import re
import patch
import winbrew
import winbrew.util
from winbrew.manifest import Manifest
from winbrew.archive import Archive


# Default arguments for the supported build tools
cmake_args = ('-G', 'Visual Studio 16 2019', '-A', 'x64')
msbuild_args = ('/P:Configuration=Release', '/p:PlatformToolset=v142', '/p:UseEnv=true')

class FormulaException(Exception):
    pass

class FormulaProxy:
    def __init__(self, formula):
        self.formula = formula

    @property
    def name(self):
        return self.formula.name

    @property

# Path: winbrew/manifest.py
# class Manifest:
#     """
#     Stores a list of all files installed by a formula.  This class is used to
#     determine which files to uninstall, and to check for conflicts between
#     formulas.
#     """
# 
#     def __init__(self, name):
#         self.files = []
#         self.name = name
#         self.status = 'uninstalled'
# 
#     def save(self):
#         """
#         Write the manifest to the manifest file directory
#         """
#         values = [(path, self.name) for path in self.files]
#         query = 'REPLACE INTO InstalledFile (path, formula) VALUES (?, ?)'
#         self.db().cursor().executemany(query, values)
# 
#         query = 'REPLACE INTO Formula (name, status) VALUES (?, ?)'
#         self.db().cursor().execute(query, (self.name, self.status))
# 
#         self.db().commit()
# 
#     def load(self):
#         """
#         Read the manifest from the manifest file directory
#         """
#         query = 'SELECT path FROM InstalledFile WHERE formula=?'
#         results = self.db().cursor().execute(query, (self.name,))
#         self.files = [result[0] for result in results]
# 
#         query = 'SELECT status FROM Formula where name=?'
#         results = self.db().cursor().execute(query, (self.name,))
#         try:
#             self.status = next(results)[0]
#         except StopIteration:
#             pass
# 
#     def delete(self):
#         """
#         Delete the manifest
#         """
#         query = 'DELETE FROM InstalledFile WHERE formula=?'
#         self.db().cursor().execute(query, (self.name,))
#         query = 'DELETE FROM Formula WHERE name=?'
#         self.db().cursor().execute(query, (self.name,))
#         self.db().commit()
# 
#     @property
#     def installed(self):
#         """
#         Returns true if the Manifest indicates the formula is installed
#         """
#         return self.status == 'installed'
# 
#     @classmethod
#     def all(self):
#         """
#         List all installed packages
#         """
#         query = 'SELECT DISTINCT formula FROM InstalledFile'
#         results = self.db().cursor().execute(query)
#         return [Manifest(result[0]) for result in results]
#         # FIXME: This may be inefficient
# 
#     @classmethod
#     def db(self):
#         if not getattr(self, '_db', None):
#             winbrew.util.mkdir_p(winbrew.manifest_path)
#             self._db = sqlite3.connect(os.path.join(winbrew.manifest_path, 'manifest.db'))
#             self.migrate()
#         return self._db
# 
#     @classmethod
#     def migrate(self):
#         """
#         Execute database migrations
#         """
#         self._db.cursor().execute("""
#         CREATE TABLE IF NOT EXISTS InstalledFile (
#             path TEXT NOT NULL UNIQUE,
#             formula TEXT NOT NULL,
#             PRIMARY KEY(path, formula)
#         )
#         """)
# 
#         self._db.cursor().execute("""
#         CREATE TABLE IF NOT EXISTS Formula (
#             name TEXT NOT NULL UNIQUE,
#             status TEXT NOT NULL,
#             PRIMARY KEY(name)
#         )
#         """)
# 
# Path: winbrew/archive.py
# class Archive:
#     """
#     Archive describes the type of package to download. Typically, some kind of
#     compressed file (tar, zip) or a git repository.
#     """
# 
#     @staticmethod
#     def create(url, work_dir, package_name):
#         ext = os.path.splitext(url)[1]
#         name = os.path.split(url)[1]
# 
#         if ext == '.zip':
#             return ZipArchive(url, work_dir, name)
#         elif ext == '.gz':
#             return TarArchive(url, work_dir, name, compression='gz')
#         elif ext == '.tgz':
#             return TarArchive(url, work_dir, name, compression='gz')
#         elif ext == '.bz2':
#             return TarArchive(url, work_dir, name, compression='bz2')
#         elif ext == '.xz':
#             return TarArchive(url, work_dir, name, compression='xz')
#         elif ext == '.msi':
#             return MsiArchive(url, work_dir, name)
#         elif ext == '.git':
#             return GitArchive(url, work_dir, package_name)
#         else:
#             raise Exception('unknown archive file type')
# 
#     def __init__(self, url, work_dir, name):
#         self.url = url
# 
#         # Parent working directory in cache
#         self.work_dir = work_dir
# 
#         # File name
#         self.name = name
# 
#         # Full downloaded file path
#         self.path = os.path.join(work_dir, name)
# 
#     def download(self):
#         winbrew.util.rm_rf(self.work_dir)
#         winbrew.util.mkdir_p(self.work_dir)
# 
#         with open(self.path, 'wb') as fd, self.urlopen() as stream:
#             shutil.copyfileobj(stream, fd)
# 
#     def urlopen(self):
#         headers = {
#             'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'
#         }
# 
#         request = urllib.request.Request(self.url, headers=headers)
#         return urllib.request.urlopen(request)
# 
#     def clean(self):
#         for fn in os.listdir(self.work_dir):
#             if fn != self.name:
#                 winbrew.util.rm_rf(os.path.join(self.work_dir, fn))
#     @property
#     def unpack_dir(self):
#         return os.path.join(self.work_dir, self.unpack_name)


# Path: winbrew/formula.py
import subprocess
import sys
import os
import errno
import glob
import shutil
import shlex
import imp
import winbrew
import argparse
import hashlib
import re
import patch
import winbrew
import winbrew.util
from winbrew.manifest import Manifest
from winbrew.archive import Archive



# Default arguments for the supported build tools
cmake_args = ('-G', 'Visual Studio 16 2019', '-A', 'x64')
msbuild_args = ('/P:Configuration=Release', '/p:PlatformToolset=v142', '/p:UseEnv=true')

class FormulaException(Exception):
    pass

class FormulaProxy:
    def __init__(self, formula):
        self.formula = formula

    @property
    def name(self):
        return self.formula.name

    @property

    def deps(self):