Exemple #1
0
def get_session_cookie():
    if exists(join(findconffolder(), "session")):
        session = open(join(findconffolder(), "session"), "r")
        cookieout = session.read()
        session.close()
        return cookieout
    else:
        return login()
Exemple #2
0
    def __init__(self):
        #Arguments for logging
        args = sys.argv[1:]
        otherargs = logging_startup(args)  # otherargs has commandspecific args
        logging.debug('hello from sync.py')

        confdir = findconffolder()
        conf = ConfigParser.ConfigParser()
        conf.read(join(confdir, 'config'))

        url = conf.get('resources', 'url')

        restful_factory = RestfulFactory(url)

        self.SimplifiedSubject = restful_factory.make("/examiner/restfulsimplifiedsubject/")
        self.SimplifiedPeriod = restful_factory.make("/examiner/restfulsimplifiedperiod/")
        self.SimplifiedAssignment = restful_factory.make("/examiner/restfulsimplifiedassignment/")
        self.SimplifiedAssignmentGroup = restful_factory.make("/examiner/restfulsimplifiedassignmentgroup/")
        self.SimplifiedDelivery = restful_factory.make("/examiner/restfulsimplifieddelivery/")
        self.SimplifiedDeadline = restful_factory.make("/examiner/restfulsimplifieddeadline/")
        self.SimplifiedStaticFeedback = restful_factory.make("/examiner/restfulsimplifiedstaticfeedback/")
        self.SimplifiedFileMeta = restful_factory.make("/examiner/restfulsimplifiedfilemeta/")

        self.root_dir = dirname(confdir) + sep
        self.metadata = {}
Exemple #3
0
    def __init__(self):
        #Arguments for logging
        args = sys.argv[1:]
        otherargs = logging_startup(args)  # otherargs has commandspecific args
        logging.debug('hello from sync.py')

        confdir = findconffolder()
        conf = ConfigParser.ConfigParser()
        conf.read(join(confdir, 'config'))

        url = conf.get('resources', 'url')

        restful_factory = RestfulFactory(url)

        self.SimplifiedSubject = restful_factory.make(
            "/examiner/restfulsimplifiedsubject/")
        self.SimplifiedPeriod = restful_factory.make(
            "/examiner/restfulsimplifiedperiod/")
        self.SimplifiedAssignment = restful_factory.make(
            "/examiner/restfulsimplifiedassignment/")
        self.SimplifiedAssignmentGroup = restful_factory.make(
            "/examiner/restfulsimplifiedassignmentgroup/")
        self.SimplifiedDelivery = restful_factory.make(
            "/examiner/restfulsimplifieddelivery/")
        self.SimplifiedDeadline = restful_factory.make(
            "/examiner/restfulsimplifieddeadline/")
        self.SimplifiedStaticFeedback = restful_factory.make(
            "/examiner/restfulsimplifiedstaticfeedback/")
        self.SimplifiedFileMeta = restful_factory.make(
            "/examiner/restfulsimplifiedfilemeta/")

        self.root_dir = dirname(confdir) + sep
        self.metadata = {}
Exemple #4
0
def login():

    confdir = findconffolder()
    conf = ConfigParser.ConfigParser()
    conf.read(join(confdir, "config"))

    # make the url and credentials
    url = join(conf.get("resources", "url"), "authenticate/login")

    username = raw_input("Username: "******"Password: "******"username": username, "password": password})

    parsed_url = urlparse(url)
    host = parsed_url.netloc

    if parsed_url.scheme == "https":
        conn = httplib.HTTPSConnection(host)
    else:
        conn = httplib.HTTPConnection(host)

    response = conn.request("POST", parsed_url.path, creds, {"Content-type": "application/x-www-form-urlencoded"})

    response = conn.getresponse()
    if response.status > 400:
        raise LoginError(
            "Login to %s failed with the following message: %s %s (%s)"
            % (url, response.status, response.reason, response.msg)
        )

    response.read()
    setcookie = response.getheader("Set-Cookie")
    if setcookie == None:
        raise LoginError(
            "Login failed. This is usually because of "
            "invalid username/password, but might be "
            "caused by wrong login urlprefix or server errors. "
            "Technical error message: Login urlprefix did not "
            "respond with any authorization cookies."
        )

    cookie = SimpleCookie()
    cookie.load(setcookie)
    cookieout = cookie.output().replace("Set-Cookie: ", "")
    session = open(join(confdir, "session"), "w")
    session.write(cookieout)
    session.close()
    chmod(join(confdir, "session"), stat.S_IRUSR | stat.S_IWUSR)

    conf.set("resources", "user", username)

    with open(join(confdir, "config"), "wb") as f:
        conf.write(f)

    return cookieout
 def __init__(self):
     self.conf = get_config()
     self.root_dir = dirname(findconffolder())
     self.metadata = get_metadata()
     self.num_groups = 0
     self.num_subjects = 0
     self.num_deliveries = 0
     self.num_feedbacks = 0
     groups_subject = 0
     groups_period = 0
     groups_assignment = 0
Exemple #6
0
def login():
    # grab the config file
    confdir = utils.findconffolder()
    conf = ConfigParser.ConfigParser()
    conf.read(join(confdir, 'config'))

    if exists(join(confdir, 'session')):
        session = open(join(confdir, 'session'), 'r')
        cookieout = session.read()
        session.close()
        return cookieout

    # make the url and credentials
    url = join(conf.get('URL', 'url'), 'authenticate/login')
    creds = urllib.urlencode({'username': '******', 'password': '******'})

    parsed_url = urlparse(url)
    host = parsed_url.netloc

    if parsed_url.scheme == "https":
        conn = httplib.HTTPSConnection(host)
    else:
        conn = httplib.HTTPConnection(host)

    response = conn.request(
        'POST', parsed_url.path, creds,
        {'Content-type': "application/x-www-form-urlencoded"})

    response = conn.getresponse()
    if response.status > 400:
        raise LoginError(
            "Login to %s failed with the following message: %s %s (%s)" %
            (url, response.status, response.reason, response.msg))

    response.read()
    setcookie = response.getheader('Set-Cookie')
    if setcookie == None:
        raise LoginError("Login failed. This is usually because of "
                         "invalid username/password, but might be "
                         "caused by wrong login urlprefix or server errors. "
                         "Technical error message: Login urlprefix did not "
                         "respond with any authorization cookies.")

    cookie = SimpleCookie()
    cookie.load(setcookie)
    cookieout = cookie.output().replace('Set-Cookie: ', '')
    session = open(join(confdir, 'session'), 'w')
    session.write(cookieout)
    session.close()

    return cookieout
Exemple #7
0
def login():
    # grab the config file
    confdir = utils.findconffolder()
    conf = ConfigParser.ConfigParser()
    conf.read(join(confdir, 'config'))

    if exists(join(confdir, 'session')):
        session = open(join(confdir, 'session'), 'r')
        cookieout = session.read()
        session.close()
        return cookieout

    # make the url and credentials
    url = join(conf.get('URL', 'url'), 'authenticate/login')
    creds = urllib.urlencode({'username': '******', 'password': '******'})

    parsed_url = urlparse(url)
    host = parsed_url.netloc

    if parsed_url.scheme == "https":
        conn = httplib.HTTPSConnection(host)
    else:
        conn = httplib.HTTPConnection(host)

    response = conn.request('POST', parsed_url.path, creds, {'Content-type': "application/x-www-form-urlencoded"})

    response = conn.getresponse()
    if response.status > 400:
        raise LoginError("Login to %s failed with the following message: %s %s (%s)" % (
                url, response.status, response.reason, response.msg))

    response.read()
    setcookie = response.getheader('Set-Cookie')
    if setcookie == None:
        raise LoginError("Login failed. This is usually because of "
                         "invalid username/password, but might be "
                         "caused by wrong login urlprefix or server errors. "
                         "Technical error message: Login urlprefix did not "
                         "respond with any authorization cookies.")

    cookie = SimpleCookie()
    cookie.load(setcookie)
    cookieout = cookie.output().replace('Set-Cookie: ', '')
    session = open(join(confdir, 'session'), 'w')
    session.write(cookieout)
    session.close()

    return cookieout
Exemple #8
0
    def __init__(self, soi=None, aoi=None):
        """
        Get the interesting values from .devilry/config

        :param soi: Subject of interest; Get only information about
        this subject

        :param aoi: Assignment of interest; Get only information about
        this assignment
        """

        self.conf_dir = findconffolder()
        self.root_dir = dirname(self.conf_dir)
        self.conf = get_config()
        self.metadata = get_metadata()

        # Read stuff from .devilry/config
        self.user = self.conf.get('resources', 'user')
        self.server = self.conf.get('resources', 'url')

        self.soi = soi
        self.aoi = aoi
Exemple #9
0
    def __init__(self, soi=None, aoi=None):
        """
        Get the interesting values from .devilry/config

        :param soi: Subject of interest; Get only information about
        this subject

        :param aoi: Assignment of interest; Get only information about
        this assignment
        """

        self.conf_dir = findconffolder()
        self.root_dir = dirname(self.conf_dir)
        self.conf = get_config()
        self.metadata = get_metadata()

        # Read stuff from .devilry/config
        self.user = self.conf.get('resources', 'user')
        self.server = self.conf.get('resources', 'url')

        self.soi = soi
        self.aoi = aoi
Exemple #10
0
 def write_metadata(self):
     devilryfolder = findconffolder()
     metafilename = join(devilryfolder, 'metadata')
     if exists(metafilename):
         rename(metafilename, join(devilryfolder, 'old_metadata'))
     save_metadata(self.metadata)
Exemple #11
0
 def __init__(self):
     self.conf_dir = findconffolder()
     self.root_dir = dirname(self.conf_dir)
Exemple #12
0
 def __init__(self):
     self.conf = get_config()
     self.root_dir = dirname(findconffolder()) + sep
     f = open(join(findconffolder(), 'metadata'), 'r')
     self.metadata = eval(f.read())
Exemple #13
0
 def __init__(self):
     self.conf = get_config()
     self.confdir = findconffolder()
     self.metadata = get_metadata()
Exemple #14
0
 def __init__(self):
     self.conf = get_config()
     self.root_dir = dirname(findconffolder()) + sep
     self.metadata = get_metadata()
Exemple #15
0
 def __init__(self):
     self.conf_dir = findconffolder()
     self.root_dir = dirname(self.conf_dir)
     self.conf = ConfigParser()
     self.conf.read(join(self.conf_dir, 'config'))
     self.server = self.conf.get('resources', 'url')
Exemple #16
0
 def write_metadata(self):
     devilryfolder = findconffolder()
     metafilename = join(devilryfolder, 'metadata')
     if exists(metafilename):
         rename(metafilename, join(devilryfolder, 'old_metadata'))
     save_metadata(self.metadata)
Exemple #17
0
 def __init__(self):
     self.conf_dir = findconffolder()
     self.root_dir = dirname(self.conf_dir)
Exemple #18
0
 def __init__(self):
     self.conf = get_config()
     self.root_dir = dirname(findconffolder()) + sep
     f = open(join(findconffolder(), 'metadata'), 'r')
     self.metadata = eval(f.read())
Exemple #19
0
 def run(self):
     #start creating directories recursively
     devilry_path = dirname(findconffolder())
     subjects = self.SimplifiedSubject.search(query='')
     self.add_subjects(devilry_path, subjects)
     self.write_metadata()
Exemple #20
0
 def run(self):
     #start creating directories recursively
     devilry_path = dirname(findconffolder())
     subjects = self.SimplifiedSubject.search(query='')
     self.add_subjects(devilry_path, subjects)
     self.write_metadata()