Пример #1
0
 def __init__(self, theme, dest_folder):
     self.dest_folder = dest_folder
     self.extensions_descs = {}
     self.theme = theme
     self.github = Github("emesene")
     self._stop = False
     self._tree = None
     self.progress = 0.0
Пример #2
0
    def setUp( self ):
        unittest.TestCase.setUp( self )

        self.g = Github( "login", "password" )

        self.requester = MockMockMock.Mock( "requester" )
        self.g._Github__requester = self.requester.object
Пример #3
0
def scrap():
    #user = request.args.get('user')
    list = []
    page = requests.get(URL + 'trending')
    soup = BeautifulSoup(page.content, 'html.parser')
    info = soup.find_all(class_='Box-row')
    for item in info:
        title = (item.find(
            class_='h3 lh-condensed').find('a').get_text()).replace(
                '\n', '').replace(' ', '')
        link = "https://github.com/" + item.find(
            class_='h3 lh-condensed').find('a')['href']
        text = item.find(class_='col-9 text-gray my-1 pr-4').get_text().strip()
        glo_language = item.find(class_='f6 text-gray mt-2').find_all(
            class_='d-inline-block ml-0 mr-3')
        for lan in glo_language:
            language = lan.find('span',
                                itemprop='programmingLanguage').get_text()
        star = item.find(
            class_='f6 text-gray mt-2').select('a')[0].get_text().strip()
        folk = item.find(
            class_='f6 text-gray mt-2').select('a')[1].get_text().strip()
        github = Github(title, link, text, language, star, folk)
        list.append(github)
        #print(github.reponseJson())

    return jsonify(trending=[e.reponseJson() for e in list])
Пример #4
0
 def __init__(self, theme, dest_folder):
     self.dest_folder = dest_folder
     self.extensions_descs = {}
     self.theme = theme
     self.github = Github("emesene")
     self._stop = False
     self._tree = None
     self.progress = 0.0
Пример #5
0
 def __init__(self, theme, dest_folder):
     self.dest_folder = dest_folder
     self.extensions_descs = {}
     self.theme = theme
     self.github = Github("emesene")
     self._stop = False
     self._stopfetch = False
     self._blobs = None
Пример #6
0
class Collection(object):

    def __init__(self, theme, dest_folder):
        self.dest_folder = dest_folder
        self.extensions_descs = {}
        self.theme = theme
        self.github = Github("emesene")
        self._stop = False
        self._tree = None
        self.progress = 0.0

    def save_files(self, type_, label):
        self._stop = False
        element = self.extensions_descs[type_].get(label)
        if element is None:
            return

        keys = element.files.keys()
        tmp_dir = tempfile.mkdtemp()
        for k, path in enumerate(keys):
            if self._stop:
                self.remove(tmp_dir)
                return

            self.progress = k / float(len(keys))

            split_path = path.split("/")
            path_to_create = tmp_dir
            for part in split_path[:-1]:
                path_to_create = os.path.join(path_to_create, part)
            try:
                os.makedirs(path_to_create)
            except OSError:
                pass

            try:
                rq = self.github.get_raw(self.theme, element.files[path])
            except Exception, ex:
                log.exception(str(ex))
                self.remove(tmp_dir)
                return

            f = open(os.path.join(path_to_create, split_path[-1]), "wb")
            f.write(rq)
            f.close()

        self.remove(self.get_abspath(type_, label))
        path = self.get_path(type_, label)
        split_path = os.path.split(path)
        first_path = split_path[0] if split_path[1] else ''
        self.move(os.path.join(tmp_dir, path), os.path.join(self.dest_folder, first_path))
        self.remove(tmp_dir)
        self.progress = 0.0
Пример #7
0
class Collection(object):

    def __init__(self, theme, dest_folder):
        self.dest_folder = dest_folder
        self.extensions_descs = {}
        self.theme = theme
        self.github = Github("emesene")
        self._stop = False
        self._stopfetch = False
        self._blobs = None

    def save_files(self, element, label):
        self._stop = False
        for el, k in element[label].files.items():
            els = el.split("/")
            if self._stop:
                self.remove(os.path.join(self.dest_folder, els[0]))
                return
            path_to_create = ""
            for i in range(len(els) - 1):
                path_to_create = os.path.join(path_to_create, els[i])
            try:
                os.makedirs(os.path.join(self.dest_folder , path_to_create))
            except OSError:
                pass
            rq = self.github.get_raw(self.theme, k)
            f = open(os.path.join(self.dest_folder, el), "wb")
            f.write(rq)
    
    def download(self, download_item=None):
        for element in self.extensions_descs.itervalues():
            if download_item is not None:
                self.save_files(element, download_item)

    def remove(self, path):
        shutil.rmtree(path)

    def stop(self):
        self._stop = True

    def stop_fetch(self):
        self._stopfetch = True

    def set_blobs(self, result):
        self._blobs = result

    def plugin_name_from_file(self, file_name):
        pass

    def fetch(self):
        pass
Пример #8
0
def main(args):
    """
    Clone an existing repo, create a Github repo and push the actual repo into it
    :param args: {path: the path to clone it, repo_url: the original repo url}
    :return:
    """
    path = os.path.join(os.getcwd(), args.path)
    try:
        subprocess.run(["git", "clone", args.repo_url, path], check=True)
    except subprocess.CalledProcessError as e:
        sys.exit("Error during git clone")
    g = Github()
    r = g.create_repo(os.path.basename(path), auto_init=False)
    os.chdir(args.path)
    try:
        subprocess.run(["git", "remote", "add", "github", r["ssh_url"]], check=True)
    except subprocess.CalledProcessError as e:
        sys.exit("Error during adding Github remote")
    try:
        subprocess.run(["git", "push", "-u", "github", "master"], check=True)
    except subprocess.CalledProcessError as e:
        sys.exit("Error during pushing to Github but repo successfully created")
    print ("Everything went well")
Пример #9
0
class Collection(object):
    def __init__(self, theme, dest_folder):
        self.dest_folder = dest_folder
        self.extensions_descs = {}
        self.theme = theme
        self.github = Github("emesene")
        self._stop = False
        self._blobs = None
        self.progress = 0.0

    def save_files(self, element, label):
        self._stop = False
        if not label in element:
            return
        keys = element[label].files.keys()
        for k, path in enumerate(keys):
            self.progress = k / float(len(keys))

            split_path = path.split("/")
            if self.theme.endswith("themes"):
                removal_path = os.path.join(self.dest_folder, split_path[0],
                                            split_path[1])
            else:
                removal_path = os.path.join(self.dest_folder, split_path[0])

            if self._stop:
                self.remove(removal_path)
                return

            path_to_create = self.dest_folder
            for part in split_path[:-1]:
                path_to_create = os.path.join(path_to_create, part)
            try:
                os.makedirs(path_to_create)
            except OSError:
                pass

            try:
                rq = self.github.get_raw(self.theme,
                                         element[label].files[path])
            except Exception, ex:
                log.error(str(ex))
                self.remove(removal_path)
                return

            f = open(os.path.join(path_to_create, split_path[-1]), "wb")
            f.write(rq)
            f.close()
        self.progress = 1.0
Пример #10
0
class Collection(object):

    def __init__(self, theme, dest_folder):
        self.dest_folder = dest_folder
        self.extensions_descs = {}
        self.theme = theme
        self.github = Github("emesene")
        self._stop = False
        self._tree = None
        self.progress = 0.0

    def save_files(self, element, label):
        self._stop = False
        if not label in element:
            return
        keys = element[label].files.keys()
        for k, path in enumerate(keys):
            self.progress = k / float(len(keys))

            split_path = path.split("/")
            if self.theme.endswith("themes"):
                removal_path = os.path.join(self.dest_folder, split_path[0], split_path[1])
            else:
                removal_path = os.path.join(self.dest_folder, split_path[0])

            if self._stop:
                self.remove(removal_path)
                return

            path_to_create = self.dest_folder
            for part in split_path[:-1]:
                path_to_create = os.path.join(path_to_create, part)
            try:
                os.makedirs(path_to_create)
            except OSError:
                pass

            try:
                rq = self.github.get_raw(self.theme, element[label].files[path])
            except Exception, ex:
                log.exception(str(ex))
                self.remove(removal_path)
                return

            f = open(os.path.join(path_to_create, split_path[-1]), "wb")
            f.write(rq)
            f.close()
        self.progress = 0.0
Пример #11
0
class Collection(object):

    def __init__(self, theme, dest_folder):
        self.dest_folder = dest_folder
        self.extensions_descs = {}
        self.theme = theme
        self.github = Github("emesene")

    def save_files(self, element, label):
        for el, k in element[label].files.items():
            els = el.split("/")
            path_to_create = ""
            for i in range(len(els) - 1):
                path_to_create = os.path.join(path_to_create, els[i])
            try:
                os.makedirs(os.path.join(self.dest_folder , path_to_create))
            except OSError:
                pass
            rq = self.github.get_raw(self.theme, k)
            f = open(os.path.join(self.dest_folder, el), "wb")
            f.write(rq)
    
    def download(self, download_item=None):
        for key in self.extensions_descs:
            element = self.extensions_descs[key]
            if download_item is not None:
                self.save_files(element, download_item)
            else:
                for label in element:
                    if element[label].todownload:
                        self.save_files(element, label)

    def plugin_name_from_file(self, file_name):
        pass


    def fetch(self):
        pass
Пример #12
0
import os
from zipfile import ZipFile
import sys
import random

TAG_VERSION = 4

jokes = None

with open("jokes.json", "r", encoding="utf-8") as file:
    jokes = json.loads(file.read())



print("INFO: Suche nach neuer Version...")
ghub = Github("chatn0ir07", "spotify-songrequests", TAG_VERSION)
releases = ghub.CheckReleases()
if releases["IsNew"]:
    filename, headers = urllib.request.urlretrieve(releases["Zipball_URL"])
    print("INFO: Neue Version unter %s gespeichert" % filename)
    print("INFO: Entpacke Archiv...")
    os.mkdir("release")
    zp = ZipFile(filename, "r")
    zp.extractall("release")
    os.remove(filename)
    print("INFO: Archiv entpackt, bitte in den \"release\" Ordner navigieren und aktuelle Datei mit der neuen ersetzen")
    input("Mit einem Tastendruck wird das Program beendet")
    sys.exit(0)
else:
    print("INFO: Keine neue Version gefunden (stand: v%s)" % TAG_VERSION)
SPOTIFYUSER = None
Пример #13
0
class TestCase( unittest.TestCase ):
    def setUp( self ):
        unittest.TestCase.setUp( self )

        self.g = Github( "login", "password" )

        self.requester = MockMockMock.Mock( "requester" )
        self.g._Github__requester = self.requester.object

    def tearDown( self ):
        self.requester.tearDown()
        unittest.TestCase.tearDown( self )

    def testCreateForkForUser( self ):
        self.requester.expect.dataRequest( "GET", "/users/xxx", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "POST", "/repos/xxx/yyy/forks", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.g.get_user().create_fork( self.g.get_user( "xxx" ).get_repo( "yyy" ) )

    def testCreateForkForOrganization( self ):
        self.requester.expect.dataRequest( "GET", "/orgs/ooo", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/users/xxx", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "POST", "/repos/xxx/yyy/forks", { "org": "ooo" }, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.g.get_organization( "ooo" ).create_fork( self.g.get_user( "xxx" ).get_repo( "yyy" ) )

    def testQueryFollowing( self ):
        self.requester.expect.dataRequest( "GET", "/users/xxx", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.statusRequest( "GET", "/user/following/xxx", None, None ).andReturn( 404 )
        self.requester.expect.dataRequest( "GET", "/users/yyy", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.statusRequest( "GET", "/user/following/yyy", None, None ).andReturn( 204 )
        self.assertFalse( self.g.get_user().has_in_following( self.g.get_user( "xxx" ) ) )
        self.assertTrue( self.g.get_user().has_in_following( self.g.get_user( "yyy" ) ) )

    def testGist( self ):
        self.requester.expect.dataRequest( "GET", "/gists/123456", None, None ).andReturn( { "description": "xxx" } )
        g = self.g.get_gist( 123456 )
        self.assertEqual( g.description, "xxx" )
        self.requester.expect.statusRequest( "GET", "/gists/123456/star", None, None ).andReturn( 404 )
        self.assertFalse( g.is_starred() )
        self.requester.expect.statusRequest( "PUT", "/gists/123456/star", None, None ).andReturn( 204 )
        g.set_starred()
        self.requester.expect.statusRequest( "DELETE", "/gists/123456/star", None, None ).andReturn( 204 )
        g.reset_starred()
        self.requester.expect.dataRequest( "POST", "/gists/123456/fork", None, None ).andReturn( { "description": "yyy" } )
        self.assertEqual( g.create_fork().description, "yyy" )
        self.requester.expect.dataRequest( "GET", "/gists/starred", None, None ).andReturn( [ { "description": "xxx" }, { "description": "yyy" } ] )
        self.assertEqual( len( self.g.get_user().get_starred_gists() ), 2 )

    def testRepositoryReference( self ):
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        r = self.g.get_user().get_repo( "yyy" )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/milestones/1", None, None ).andReturn( { "number": 1 } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/milestones/1/labels", {}, None ).andReturn( [ { "name": "a" } ] )
        self.assertIs( r.get_milestone( 1 ).get_labels()[ 0 ]._repo, r )

    def testHooks( self ):
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/hooks/1", None, None ).andReturn( { "name": "web", "id": 1 } )
        h = self.g.get_user().get_repo( "yyy" ).get_hook( 1 )
        self.requester.expect.statusRequest( "POST", "/repos/xxx/yyy/hooks/1/test", None, None ).andReturn( 204 )
        h.test()

    def testUserEvents( self ):
        self.requester.expect.dataRequest( "GET", "/users/xxx", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/users/xxx/events/public", None, None ).andReturn( [] )
        self.requester.expect.dataRequest( "GET", "/users/xxx/received_events/public", None, None ).andReturn( [] )
        u = self.g.get_user( "xxx" )
        u.get_public_events()
        u.get_public_received_events()

    def testRepoEvents( self ):
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "GET", "/networks/xxx/yyy/events", None, None ).andReturn( [] )
        r = self.g.get_user().get_repo( "yyy" )
        r.get_network_events()

    def testOrgEvents( self ):
        self.requester.expect.dataRequest( "GET", "/orgs/ooo", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/users/xxx/events/orgs/ooo", None, None ).andReturn( [] )
        u = self.g.get_user()
        o = self.g.get_organization( "ooo" )
        u.get_organization_events( o )

    def testMergePullRequest( self ):
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/pulls/42", None, None ).andReturn( { "number": 42 } )
        self.requester.expect.statusRequest( "GET", "/repos/xxx/yyy/pulls/42/merge", None, None ).andReturn( 404 )
        self.requester.expect.statusRequest( "PUT", "/repos/xxx/yyy/pulls/42/merge", None, {} ).andReturn( 204 )
        self.requester.expect.statusRequest( "GET", "/repos/xxx/yyy/pulls/42/merge", None, None ).andReturn( 204 )
        p = self.g.get_user().get_repo( "yyy" ).get_pull( 42 )
        self.assertFalse( p.is_merged() )
        p.merge()
        self.assertTrue( p.is_merged() )

    def testRepositoryCompare( self ):
        self.requester.expect.dataRequest( "GET", "/user", None, None ).andReturn( { "login": "******" } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy", None, None ).andReturn( { "name": "yyy", "owner": { "login": "******" } } )
        self.requester.expect.dataRequest( "GET", "/repos/xxx/yyy/compare/foo...bar", None, None ).andReturn( { "gabu": "zomeuh" } )
        self.assertEqual( self.g.get_user().get_repo( "yyy" ).compare( "foo", "bar" ), { "gabu": "zomeuh" } )
Пример #14
0
 def __init__(self, theme, dest_folder):
     self.dest_folder = dest_folder
     self.extensions_descs = {}
     self.theme = theme
     self.github = Github("emesene")