Ejemplo n.º 1
0
 def set_version(self):
     self.versions = []
     bad_version_tags = []
     for v in sorted(
             self.repo('tag --merged').decode('utf-8').splitlines()):
         try:
             self.versions.append(Version(v))
         except:
             bad_version_tags.append(v)
     if bad_version_tags:
         log.warning(f"package {self.link} has invalid version tags:")
         for v in bad_version_tags:
             print(' ', v)
         log.info('you can fix this issue using: \n'
                  '  git push --delete origin tagName\n'
                  '  git tag -d tagName')
     # get version
     versions = sorted(self.specifier.filter(self.versions))
     if not versions:
         raise VersionFilterError(
             f"pkg {self.link} with specifiers {self.specifier} "
             f"has no valid version from its versions list: {self.versions}"
         )
     self.version = versions[-1]
     self.repo(f'checkout tags/{self.version.__str__()}')
    def create_package_file(self):
        if os.path.exists(self.pkg):
            log.warning("package.py already exist and may be used for other functionality")
        else:
            key, token = encrypt(
                url=self.git.url,
                email=self.git.email,
                username=self.git.username,
                password=self.git.password,
                pypi_user=self.pypi_user,
                pypi_pass=self.pypi_pass,
            )
            upload = "\n        lambda: manager.upload()," if self.pypi_user and self.pypi_pass else ""
            with open(self.pkg, 'w') as f:
                f.write(f'''from qaviton_package_manager import Manager, decypt


manager = Manager(**decypt(
    key={key},
    token={token},
))


if __name__ == "__main__":
    manager.run(
        lambda: manager.update(),
        lambda: manager.update_test(),
        lambda: manager.test(),
        lambda: manager.build(),{upload}
    )
'''                     )
        log.info('created package.py file')
 def handle_git_ignore(self):
     if not os.path.exists(self.git_ignore):
         log.warning("missing .gitignore file")
         print('creating .gitignore file')
         with open(self.git_ignore, 'w') as f:
             f.write('\n'.join(ignore_list))
         self.git.add('"'+self.git_ignore+'"')
     else:
         with open(self.git_ignore) as f:
             lines = f.read().splitlines()
         with open(self.git_ignore, 'a') as f:
             f.write('\n'+'\n'.join([line for line in ignore_list if line not in lines]))
     log.info('added content to .gitignore file')
 def get_readme(self):
     readme = self.root + os.sep + SETTINGS.README
     if not os.path.exists(readme):
         log.warning(f'{SETTINGS.README} not found\nP.S. you can change the default readme filename with qaviton_package_manager.conf.SETTINGS.README = "filename"')
         name = prompt(f'select README filename({SETTINGS.README} default):')
         if not name: name = SETTINGS.README
         else: SETTINGS.README = name
         readme = self.root + os.sep + name
         if not os.path.exists(readme):
             print(f'creating file: {readme}')
             with open(readme, 'w') as f:
                 f.write(self.package_name.replace('_', ' '))
             self.git.add('"'+readme+'"')
     return readme
    def __init__(self, git: Git, pypi_user, pypi_pass, package_name=None):
        log.info("creating git packaging system")
        log.info("press q to quit")

        if package_name is None:
            self.package_name = git.root.rsplit(os.sep, 1)[1]
            log.warning('package name not specified, selecting dir name:', self.package_name)
        else:
            self.package_name = package_name

        Prep.__init__(self, git, self.package_name)

        self.pypi_user = pypi_user
        self.pypi_pass = pypi_pass
        self.git_ignore = self.root + os.sep + SETTINGS.GIT_IGNORE
        self.pkg = self.root + os.sep + SETTINGS.PACKAGE
        self.run()
    def get_license(self):
        license = self.root + os.sep + SETTINGS.LICENSE
        key = None
        if not os.path.exists(license):
            log.warning(f'{SETTINGS.LICENSE} not found\nP.S. you can change the default license filename with qaviton_package_manager.conf.SETTINGS.LICENSE = "filename"')
            name = prompt(f'select LICENSE filename({SETTINGS.LICENSE} default):')
            if not name: name = SETTINGS.LICENSE
            else: SETTINGS.LICENSE = name
            license = self.root + os.sep + name
            if not os.path.exists(license):
                key = select_license()
                print(f'creating file: {license}')
                if key != "private":
                    http = HTTP.get()
                    r = http.get(f'https://api.github.com/licenses/{key}')
                    r.raise_for_status()
                    content = r.json()['body']
                else:
                    date = datetime.utcnow()
                    if not SETTINGS.COMPANY: SETTINGS.COMPANY = self.git.username
                    if not SETTINGS.OWNER: SETTINGS.OWNER = self.git.username
                    if not SETTINGS.EMAIL: SETTINGS.EMAIL = self.git.email

                    company_name = prompt(f"enter your company name({SETTINGS.COMPANY} default):")
                    full_name = prompt(f"enter legal owner full name({SETTINGS.OWNER} default):")
                    email = prompt(f"enter legal owner's email({SETTINGS.EMAIL} default):")

                    if not company_name: company_name = SETTINGS.COMPANY
                    else: SETTINGS.COMPANY = company_name

                    if not full_name: full_name = SETTINGS.OWNER
                    else: SETTINGS.OWNER = full_name

                    if not email: email = SETTINGS.EMAIL
                    else: SETTINGS.EMAIL = email

                    content = (f"Copyright © {company_name} Systems, Inc - All Rights Reserved\n"
                               "Unauthorized copying of this file\directory & all its contents,\n"
                               "via any medium is strictly prohibited\n"
                               "Proprietary and confidential\n"
                               f"Written by {full_name} <{email}>, {date.strftime('%B')} {date.year}\n")
                with open(license, 'w') as f:
                    f.write(content)
                self.git.add('"'+license+'"')
        return {'file': license, 'key': key}
Ejemplo n.º 7
0
def main():
    from os.path import exists
    from os import getcwd, sep
    root = getcwd()
    pkg = root + sep + 'package.py'
    if exists(pkg):
        from qaviton_helpers import import_path
        try:
            manager = import_path(pkg).manager
        except Exception as e:
            from qaviton_package_manager.utils.logger import log
            log.warning(e)
            log.info(f"could not retrieve 'manager' parameter from {pkg}")
            log.info("creating a new manager")
        else:
            return manager.run()
    from qaviton_package_manager.manager import Manager
    return Manager().run()
Ejemplo n.º 8
0
 def get_pkg_init(self):
     if not os.path.exists(self.pkg_path):
         log.warning(f"direcotory: {self.pkg_path} is missing")
         print("creating package...")
         os.mkdir(self.pkg_path)
         open(self.pkg_init, 'w').close()
         self.git.add('"' + self.pkg_init + '"')
         init = b''
     elif not os.path.exists(self.pkg_init):
         log.warning(f"file: {self.pkg_init} is missing")
         print("creating package init file...")
         open(self.pkg_init, 'w').close()
         self.git.add('"' + self.pkg_init + '"')
         init = b''
     else:
         with open(self.pkg_init, 'rb') as f:
             init = f.read()
     return init
    def run(self):
        log.info("asserting package __init__.py file")
        init_content = self.get_pkg_init()

        log.info("asserting package LICENSE")
        license = self.get_license()

        log.info("asserting package README")
        readme = self.get_readme()

        log.info("asserting package requirements")
        requirements = self.set_requirements()

        log.info("asserting package testing requirements")
        self.set_test_requirements()

        if os.path.exists(self.setup_path):
            log.warning("setup.py already exist")
        else:
            package_params = self.handle_package_init(init_content, license)
            self.create_setup_file(readme, requirements, package_params)
        self.create_package_file()
        self.handle_git_ignore()
        self.handle_venv()
    def handle_package_init(self, init_content: bytes, license: dict):
        package_params = {}

        tmp = b'\n' + init_content
        if b'\n__author__' not in tmp:
            log.warning(f'missing __author__ in init file')
            package_params['author'] = b'"' + escape(self.git.username).encode('utf-8') + b'"'
        else:
            package_params['author'] = tmp.split(b'\n__author__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()

        if b'\n__version__' not in tmp:
            log.warning(f'missing __version__ in init file')
            package_params['version'] = b'"0.0.1"'
        else:
            package_params['version'] = tmp.split(b'\n__version__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()

        if b'\n__author_email__' not in tmp:
            log.warning(f'missing __author_email__ in init file')
            package_params['email'] = b'"' + escape(self.git.email).encode('utf-8') + b'"'
        else:
            package_params['email'] = tmp.split(b'\n__author_email__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()

        if b'\n__description__' not in tmp:
            description = self.package_name.replace('_', ' ')
            log.warning(f'missing __description__ in init file')
            package_params['description'] = b'"' + description.encode('utf-8') + b'"'
        else:
            package_params['description'] = tmp.split(b'\n__description__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()

        if b'\n__url__' not in tmp:
            log.warning(f'missing __url__ in init file')
            package_params['url'] = b'"' + escape(self.git.url.replace('.git', '')).encode('utf-8') + b'"'
        else:
            package_params['url'] = tmp.split(b'\n__url__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()

        if b'\n__license__' not in tmp:
            if license["key"] is None:
                license["key"] = select_license()
            log.warning(f'missing __license__ in init file')
            package_params['license'] = b'"' + license["key"].encode('utf-8') + b'"'
        else:
            package_params['license'] = tmp.split(b'\n__license__', 1)[1].split(b'=', 1)[1].split(b'\n', 1)[0].strip()
        return package_params