Completed
Pull Request — master (#112)
by Jasper
01:10
created

Users.determineUser()   A

Complexity

Conditions 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 21
rs 9.3142
1
import getpass
2
3
class Users(object):
4
5
    def __init__(self, dependencies):
6
        self.config = dependencies.getConfiguration()
7
8
    def determineUser(self, passedUserValue):
9
        """Determine the name of the user creating provenance.
10
11
        The following methods will be tried to determine the username;
12
        1) The passedUserValue argument if not None
13
        2) The configuration file or setting has a value for the key user
14
        3) The OS username.
15
16
        Args:
17
            passedUserValue (str): This value will override any other method
18
                to determine the username.
19
20
        Returns:
21
            string: The username or handle of the user.
22
        """
23
        if passedUserValue is not None:
24
            return passedUserValue
25
        if self.config.user:
26
            return self.config.user
27
        else:
28
            return getpass.getuser()
29