Esempio n. 1
0
    def twisted_error(self, failure):
        # TODO: throw a message in a less invasive way
        from ErrorDialog import ErrorDialog

        dialog = ErrorDialog()
        dialog.set_from_failure(failure)
        dialog.show_all()
Esempio n. 2
0
    def twisted_error(self, failure):
        dialog = ErrorDialog()
        dialog.set_from_failure(failure)
        dialog.show_all()

        log.err(failure, 'Exception in %s' % self.__gtype_name__)
        return failure
Esempio n. 3
0
    def sign_in(self, widget):
        """
      Sign in - btn_signin action.
      :param widget: widget
    """
        user_id = self.username.get_text()
        command = 'curl -u "' + self.username.get_text(
        ) + '":"' + self.password.get_text() + '" https://api.github.com'
        out = os.popen(command).read()
        out_dict = json.loads(out)
        print("LOGIN RESPONSE: ", out, out_dict)

        if ('message' in out_dict
            ):  # response contains only has message if it's bad credentials
            ErrorDialog(self, "Invalid user name or password!")
        else:
            print("login sucessful")
            command = 'curl https://api.github.com/users/' + self.username.get_text(
            ).split('@')[0]
            out = os.popen(command).read()
            out_dict = json.loads(out)
            print("user RESPONSE: ", out, out_dict)
            print('ID IS:', out_dict['id'])
            from screen_add_project import MainWindow
            win = MainWindow(user_id, out_dict['id'])
            self.destroy()
Esempio n. 4
0
 def is_valid_url(self, url):
     if 'http://' not in url or '/connect/tmp' not in url:
         ErrorDialog(self, "Error!\nInvalid Project URL!")
         return False
     try:
         r = requests.get(url)
         if r.status_code != 200:
             ErrorDialog(
                 self, "Error!\nUnable to connect to project! Invalid URL!")
             return False
     except requests.exceptions.ConnectionError:
         ErrorDialog(self, "Error!\nUnable to connect to Susereum server!")
         return False
     if '[about]' not in r.text:
         ErrorDialog(self, "Error!\nInvalid file at " + url)
         return False
     return True
Esempio n. 5
0
    def twisted_error(self, failure):
        dialog = ErrorDialog()
        dialog.set_from_failure(failure)
        dialog.show_all()

        log.err(failure, 'Exception in %s' % self.__gtype_name__)
        return failure
Esempio n. 6
0
    def accept_proposal(self, widget):
        """
        accept_proposal - to accept the proposal
        :param widget: widget
        """
        print("Accepting project")
        print("Rejecting project")
        #check locker

        proposal_id = subprocess.check_output([
            'python3',
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
            '/Sawtooth/bin/code_smell.py', 'list', '--type', 'proposal',
            '--active', '1', '--url', 'http://127.0.0.1:' + self.api
        ])
        proposal_id = proposal_id.decode('utf-8').split(' ')[0]
        try:
            clocker = open('votelock.txt', 'r').read()
            if proposal_id in clocker:
                ErrorDialog(self, "You already voted!")
                return
        except:
            pass
        print([
            'python3',
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
            '/Sawtooth/bin/code_smell.py', 'vote', '--id', proposal_id,
            '--vote', 'yes', '--url', 'http://127.0.0.1:' + self.api
        ])
        subprocess.Popen([
            'python3',
            os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
            '/Sawtooth/bin/code_smell.py', 'vote', '--id', proposal_id,
            '--vote', 'yes', '--url', 'http://127.0.0.1:' + self.api
        ])
        locker = open('votelock.txt', 'w')
        locker.write(proposal_id)
        locker.close()

        #self.txt_accept = Gtk.Entry()
        #self.txt_accept.set_text(str(votes.count(1)))
        #self.txt_accept.set_sensitive(False)
        #hbox_lb2.pack_start(self.txt_accept, True, True, 0)
        try:
            vote = int(self.lbl_accept.get_text().split(":")[1][1:]) + 1
            self.lbl_accept.set_text(self.lbl_accept.get_text().split(":")[0] +
                                     " " + str(vote))
        except:
            pass
Esempio n. 7
0
 def error(failure):
     dialog = ErrorDialog(self.get_toplevel())
     dialog.set_from_failure(failure)
     dialog.show_all()
Esempio n. 8
0
 def twisted_error(self, failure):
     from ErrorDialog import ErrorDialog
     dialog = ErrorDialog()
     dialog.set_from_failure(failure)
     dialog.show_all()
Esempio n. 9
0
 def twisted_error(self, failure):
     from ErrorDialog import ErrorDialog
     dialog = ErrorDialog()
     dialog.set_from_failure(failure)
     dialog.show_all()
Esempio n. 10
0
 def twisted_error(self, failure):
     #TODO: throw a message in a less invasive way
     from ErrorDialog import ErrorDialog
     dialog = ErrorDialog()
     dialog.set_from_failure(failure)
     dialog.show_all()
Esempio n. 11
0
 def showError(self, errorCode, errorMsg):
     if errorCode in self.fatelErrors:
         print("Fatal Error")
         error = ErrorDialog(self.root, errorMsg, errorCode, True)
     else:
         error = ErrorDialog(self.root, errorMsg, errorCode)
Esempio n. 12
0
 def error(failure):
     dialog = ErrorDialog(self.get_toplevel())
     dialog.set_from_failure(failure)
     dialog.show_all()
Esempio n. 13
0
    def is_valid_proposal(self):
        int_measures = {
            'Large class': self.txt_large_class.get_text(),
            'Small class': self.txt_small_class.get_text(),
            'Large method': self.txt_large_method.get_text(),
            'Small method': self.txt_small_method.get_text(),
            'Large param': self.txt_large_param.get_text(),
            'God class': self.txt_god_class.get_text(),
            'Inappropriate Intimacy': self.txt_inapp_intm.get_text()
        }

        float_measures = {
            'Comments to code ratio [upper]': self.txt_ctc_up.get_text(),
            'Comments to code ratio [lower]': self.txt_ctc_lw.get_text()
        }

        for key, value in int_measures.items():
            try:
                int_measures[key] = int(value)
                if int_measures[key] < 0:
                    ErrorDialog(self,
                                "Error!\n" + key + " cannot be negative!")
                    return False
            except ValueError:
                ErrorDialog(self, "Error!\n" + key + " must be an integer!")
                return False

        for key, value in float_measures.items():
            try:
                float_measures[key] = float(value)
                if float_measures[key] < 0:
                    ErrorDialog(self,
                                "Error!\n" + key + " cannot be negative!")
                    return False
            except ValueError:
                ErrorDialog(self,
                            "Error!\n" + key + " must be a decimal value!")
                return False

        if self.tog_large_class.get_active() and self.tog_small_class.get_active() and \
                int_measures['Small class'] > int_measures['Large class']:
            ErrorDialog(
                self, "Error!\nSmall class cannot be larger than Large class!")
            return False

        if self.tog_large_method.get_active() and self.tog_small_method.get_active() and \
                int_measures['Small method'] > int_measures['Large method']:
            ErrorDialog(
                self,
                "Error!\nSmall method cannot be larger than Large method!")
            return False

        if float_measures['Comments to code ratio [lower]'] > float_measures[
                'Comments to code ratio [upper]']:
            ErrorDialog(
                self,
                "Error!\nComments to code ratio: Lower cannot be greater than Upper!"
            )
            return False

        lastest_proposal_command = 'python3 ' + os.path.dirname(
            os.path.dirname(os.path.realpath(__file__).strip()).strip()).strip() + \
                                   '/Sawtooth/bin/code_smell.py list --type proposal --active 1 --url http://127.0.0.1:' + self.api + \
                                   ' | awk \'{print $1;}\' | tr -d "\n"'
        print(lastest_proposal_command)
        self.lastest_proposal = os.popen(
            lastest_proposal_command).read().strip()
        if self.lastest_proposal == "Error: No transactions found":
            self.lastest_proposal = None
        if self.lastest_proposal:
            ErrorDialog(self, "Error!\nThere is an active proposal")
            return False
        else:
            ErrorDialog(self, "Your proposal was sent. Time to vote!")

        return True
Esempio n. 14
0
    def are_valid_smells(self):
        int_measures = {
            'Large class': self.txt_large_class.get_text(),
            'Small class': self.txt_small_class.get_text(),
            'Large method': self.txt_large_method.get_text(),
            'Small method': self.txt_small_method.get_text(),
            'Large param': self.txt_large_param.get_text(),
            'God class': self.txt_god_class.get_text(),
            'Inappropriate Intimacy': self.txt_inapp_intm.get_text(),
            'Proposal active days': self.txt_pro_act.get_text(),
            'Approval threshold': self.txt_app_tre.get_text()
        }

        float_measures = {
            'Comments to code ratio [upper]': self.txt_ctc_up.get_text(),
            'Comments to code ratio [lower]': self.txt_ctc_lw.get_text()
        }

        for key, value in int_measures.items():
            try:
                int_measures[key] = int(value)
                if int_measures[key] < 0:
                    ErrorDialog(self,
                                "Error!\n" + key + " cannot be negative!")
                    return False
            except ValueError:
                ErrorDialog(self, "Error!\n" + key + " must be an integer!")
                return False

        for key, value in float_measures.items():
            try:
                float_measures[key] = float(value)
                if float_measures[key] < 0:
                    ErrorDialog(self,
                                "Error!\n" + key + " cannot be negative!")
                    return False
            except ValueError:
                ErrorDialog(self,
                            "Error!\n" + key + " must be a decimal value!")
                return False

        if self.tog_large_class.get_active() and self.tog_small_class.get_active() and \
                int_measures['Small class'] > int_measures['Large class']:
            ErrorDialog(
                self, "Error!\nSmall class cannot be larger than Large class!")
            return False

        if self.tog_large_method.get_active() and self.tog_small_method.get_active() and \
                int_measures['Small method'] > int_measures['Large method']:
            ErrorDialog(
                self,
                "Error!\nSmall method cannot be larger than Large method!")
            return False

        if float_measures['Comments to code ratio [lower]'] > float_measures[
                'Comments to code ratio [upper]']:
            ErrorDialog(
                self,
                "Error!\nComments to code ratio: Lower cannot be greater than Upper!"
            )
            return False
        return True