Ejemplo n.º 1
0
 def select_file(cls):
     """
     Shows a GUI for file selection, selected txt file will be read and its contents will be returned
     :return note: string read from txt file
     """
     note = ''
     if module_exists('Tkinter'):
         from Tkinter import Tk
         import tkFileDialog
         root = Tk()
         root.filename = tkFileDialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("text files","*.txt"),("all files","*.*")))
     if module_exists('tkinter'):
         import tkinter
         from tkinter import filedialog
         root = tkinter.Tk()
         root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("text files","*.txt"),("all files","*.*")))
     if not root.filename:
         root.destroy()
         cancel_input = yes_no("Would you like to add a release note?")
         if cancel_input is True:
             cls.select_input()
         else:
             return False
     else:
         with open(root.filename, 'r') as file_notes:
             lines = file_notes.readlines()
         for line in lines:
             note += line
     if note == '':
         note = False
     return note
Ejemplo n.º 2
0
    def upload_to_onedrive(cls):
        """
        Upload file to onedrive
        :return ret: NO_ERROR if upload was successfull. Otherwise returns error code
        """
        ret = NO_ERROR

        if not (module_exists('onedrivesdk') and module_exists('onedrivecmd')
                and module_exists('progress') and module_exists('requests')):
            cls.init()

        file_name = cls.zip_name
        # Full path of the file to be uploaded
        file_path = r'./' + file_name
        dir_name_onedrive = 'WebRTC'

        upload = [
            'onedrivecmd', 'put', file_path, 'od:/' + dir_name_onedrive + '/'
        ]
        list_files = ['onedrivecmd', 'list', 'od:/' + dir_name_onedrive + '/']

        call(upload)

        p = Popen(list_files, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = p.communicate()

        if err:
            ret = ERROR_UPLOAD_BACKUP_FAILED
            cls.logger.error(err)
        if file_name in output:
            ret = NO_ERROR
        else:
            ret = ERROR_UPLOAD_BACKUP_FAILED

        return ret
Ejemplo n.º 3
0
    def init(cls):
        """
        Initiates logger object.
        Starts the authentication process.
        """
        cls.logger = Logger.getLogger('UploadBackup')
        cls.logger.warning(
            "The authentication process for uploading backup to OneDrive will be started, please follow the instructions."
        )
        # Install onedrivesdk package if not installed, and import it
        if module_exists('onedrivesdk') and module_exists(
                'onedrivecmd') and module_exists('progress') and module_exists(
                    'requests'):
            import onedrivesdk
            import onedrivecmd
            import progress
            import requests
        else:
            install('onedrivesdk')
            install('onedrivecmd')
            install('progress')
            install('requests')
            import onedrivesdk
            import onedrivecmd
            import progress
            import requests

        init = ['onedrivecmd', 'init']
        call(init)
Ejemplo n.º 4
0
 def download_nuget(cls):
   """
     Download latest nuget.exe file from nuget.org
   """
   # Python 3:
   if module_exists('urllib.request'):
     import urllib
     cls.logger.info('Downloading NuGet.exe file with urllib.request...')
     urllib.request.urlretrieve(config.NUGET_URL, Settings.nugetExecutablePath)
   elif module_exists('urllib2'):  # Python 2:
     import urllib2
     cls.logger.info('Downloading NuGet.exe file with urllib2...')
     with open(Settings.nugetExecutablePath, 'wb') as f:
       f.write(urllib2.urlopen(config.NUGET_URL).read())
       f.close()
   cls.logger.info("Download Complete!")
Ejemplo n.º 5
0
    def get_versions(cls, target):
        """
        Get NuGet package versions from nuget.org
        :param target: webrtc and/or ortc
        :return: NO_ERROR if successfull. Otherwise returns error code
        """
        ret = NO_ERROR
        # Works only if number of published versions of the nuget packet is less than 500
        search = 'https://api-v2v3search-0.nuget.org/search/query?q=packageid:' + target + '&ignoreFilter=true&prerelease=true&take=500'

        cls.logger.info('Collecting ' + target +
                        ' NuGet package versions from nuget.org...')
        try:
            # Python 3:
            if module_exists('urllib.request'):
                import urllib.request
                with urllib.request.urlopen(search) as url:
                    data = json.loads(url.read().decode())
            # Python 2:
            if module_exists('urllib.request') is False:
                import urllib
                response = urllib.urlopen(search)
                data = json.loads(response.read())
            data_array = data['data']

            versions = []
            for item in data_array:
                for key, val in item.items():
                    if key == 'Version':
                        versions.append(val)
            versions = set(versions)
            versions = sorted(versions)
            if versions:
                cls.versions = versions
            else:
                ret = ERROR_GET_NUGET_PACKAGE_VERSIONS_FAILED
                cls.logger.error(
                    "Failed to collect NuGet package version numbers for target: "
                    + target)
        except Exception as error:
            cls.logger.error(str(error))
            cls.logger.error(
                "Failed to collect NuGet package version numbers for target: "
                + target)
            ret = ERROR_GET_NUGET_PACKAGE_VERSIONS_FAILED
        return ret
Ejemplo n.º 6
0
    def download_nuget(cls):
        """
        Download latest nuget.exe file from nuget.org
        """
        if not os.path.exists(cls.nugetFolderPath):
            os.makedirs(cls.nugetFolderPath)
        # Python 3:
        if module_exists('urllib.request'):
            import urllib
            cls.logger.info(
                'Downloading NuGet.exe file with urllib.request...')
            urllib.request.urlretrieve(config.NUGET_URL, cls.nugetExePath)

        # Python 2:
        if module_exists('urllib2'):
            import urllib2
            cls.logger.info('Downloading NuGet.exe file with urllib2...')
            with open(cls.nugetExePath, 'wb') as f:
                f.write(urllib2.urlopen(config.NUGET_URL).read())
                f.close()
        cls.logger.info("Download Complete!")