Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: zynga/jasy
...
head fork: zynga/jasy
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 16, 2012
Sebastian Werner Minor fix + version bump 4d64407
Commits on Apr 17, 2012
Sebastian Werner Reworked file handling to allow manually added files 040d956
Sebastian Werner Added removeFile() ed6006b
Sebastian Werner Added getProjectByName() to env 8cbc1a5
Sebastian Werner Doc fixes 357533a
Sebastian Werner Added getGitBranch b48ddbe
Sebastian Werner Minor changes efd7aa2
Sebastian Werner Minor tweaks 7c29178
Sebastian Werner Added new util class 1c64071
View
2  jasy/__init__.py
@@ -3,5 +3,5 @@
# Copyright 2010-2012 Zynga Inc.
#
-__version__ = "0.6"
+__version__ = "0.6.1"
__author__ = "Sebastian Werner <info@sebastian-werner.net>"
View
96 jasy/core/Project.py
@@ -290,53 +290,61 @@ def addDir(self, directory, distname):
if fileName[0] == ".":
continue
-
+
relPath = os.path.normpath(os.path.join(relDirPath, fileName)).replace(os.sep, "/")
fullPath = os.path.join(dirPath, fileName)
- fileExtension = os.path.splitext(fileName)[1]
-
- # Prepand package
- if self.__package:
- fileId = "%s/" % self.__package
- else:
- fileId = ""
-
- # Structure files
- if fileExtension in classExtensions:
- fileId += os.path.splitext(relPath)[0]
- construct = Class
- dist = self.classes
- elif fileExtension in translationExtensions:
- fileId += os.path.splitext(relPath)[0]
- construct = Translation
- dist = self.translations
- elif fileName in docFiles:
- fileId += os.path.dirname(relPath)
- fileId = fileId.strip("/") # edge case when top level directory
- construct = Doc
- dist = self.docs
- else:
- fileId += relPath
- construct = Asset
- dist = self.assets
-
- # Only assets keep unix style paths identifiers
- if construct != Asset:
- fileId = fileId.replace("/", ".")
+
+ self.addFile(relPath, fullPath, distname)
+
+
+ def addFile(self, relPath, fullPath, distname, override=False):
+
+ fileName = os.path.basename(relPath)
+ fileExtension = os.path.splitext(fileName)[1]
+
+ # Prepand package
+ if self.__package:
+ fileId = "%s/" % self.__package
+ else:
+ fileId = ""
+
+ # Structure files
+ if fileExtension in classExtensions:
+ fileId += os.path.splitext(relPath)[0]
+ construct = Class
+ dist = self.classes
+ elif fileExtension in translationExtensions:
+ fileId += os.path.splitext(relPath)[0]
+ construct = Translation
+ dist = self.translations
+ elif fileName in docFiles:
+ fileId += os.path.dirname(relPath)
+ fileId = fileId.strip("/") # edge case when top level directory
+ construct = Doc
+ dist = self.docs
+ else:
+ fileId += relPath
+ construct = Asset
+ dist = self.assets
+
+ # Only assets keep unix style paths identifiers
+ if construct != Asset:
+ fileId = fileId.replace("/", ".")
+
+ # Validate destination (docs are okay for all other destinations)
+ if not dist is self.docs and dist != getattr(self, distname):
+ logging.info(" - Ignoring file: %s" % fileId)
+ return
+
+ # Check for duplication
+ if fileId in dist and not override:
+ raise JasyError("Item ID was registered before: %s" % fileId)
+
+ # Create instance
+ item = construct(self, fileId).attach(fullPath)
+ logging.debug(" - Registering %s %s" % (item.kind, fileId))
+ dist[fileId] = item
- # Validate destination (docs are okay for all other destinations)
- if not dist is self.docs and dist != getattr(self, distname):
- logging.info(" - Ignoring file: %s" % fileId)
- continue
-
- # Check for duplication
- if fileId in dist:
- raise JasyError("Item ID was registered before: %s" % fileId)
-
- # Create instance
- item = construct(self, fileId).attach(fullPath)
- logging.debug(" - Registering %s %s" % (item.kind, fileId))
- dist[fileId] = item
View
21 jasy/core/Repository.py
@@ -6,12 +6,31 @@
import subprocess, os, logging, hashlib, shutil, re, tempfile, sys
from urllib.parse import urlparse
-__all__ = ["cloneGit", "isGitRepositoryUrl"]
+__all__ = ["cloneGit", "isGitRepositoryUrl", "getGitBranch"]
__nullDevice = open(os.devnull, 'w')
__gitAccountUrl = re.compile("([a-zA-Z0-9-_]+)@([a-zA-Z0-9-_\.]+):([a-zA-Z0-9/_-]+\.git)")
__gitHash = re.compile(r"^[a-f0-9]{40}$")
__versionNumber = re.compile(r"^v?([0-9\.]+)(-?(a|b|rc|alpha|beta)([0-9]+)?)?\+?$")
+__branchParser = re.compile("^ref:.*/([a-zA-Z0-9_-]+)$")
+
+
+def getGitBranch(path=None):
+ """Returns the name of the git branch"""
+
+ if path is None:
+ path = os.getcwd()
+
+ headfile = os.path.join(path, ".git/HEAD")
+ if not os.path.exists(headfile):
+ raise Exception("Invalid GIT project path: %s" % path)
+
+ match = __branchParser.match(open(headfile).read())
+ if match is not None:
+ return match.group(1)
+
+ return None
+
def getDistFolder(repo, rev):
View
16 jasy/core/Util.py
@@ -0,0 +1,16 @@
+#
+# Jasy - Web Tooling Framework
+# Copyright 2010-2012 Zynga Inc.
+#
+
+import hashlib
+
+def sha1File(f, block_size=2**20):
+ sha1 = hashlib.sha1()
+ while True:
+ data = f.read(block_size)
+ if not data:
+ break
+ sha1.update(data)
+
+ return sha1.hexdigest()
View
9 jasy/env/File.py
@@ -16,6 +16,15 @@ def removeDir(dirname):
shutil.rmtree(dirname)
+def removeFile(filename):
+ """Removes the given file"""
+
+ filename = prependPrefix(filename)
+ if os.path.exists(filename):
+ logging.info("Deleting file %s" % filename)
+ os.remove(filename)
+
+
def makeDir(dirname):
"""Creates missing hierarchy levels for given directory"""
View
9 jasy/env/Session.py
@@ -134,17 +134,12 @@ def addProject(self, project):
def getProjects(self):
- """
- Returns all currently known projects.
- """
-
+ """Returns all currently known projects."""
return self.__projects
def getRelativePath(self, project):
- """
- Returns the relative path of any project to the main project
- """
+ """Returns the relative path of any project to the main project"""
mainPath = self.__projects[-1].getPath()
projectPath = project.getPath()
View
2  jasy/env/State.py
@@ -96,6 +96,8 @@ def prependPrefix(path):
# ---------------------------------------------
from jasy.env.Session import Session
+from jasy.core.Project import getProjectByName
+
session = Session()
View
1  jasy/env/Task.py
@@ -5,6 +5,7 @@
import types, logging, os
from jasy.env.State import setPrefix, startSection, session, getPrefix
+from jasy.core.Error import JasyError
__all__ = ["task", "executeTask", "runTask", "printTasks", "setJasyCommand"]

No commit comments for this range

Something went wrong with that request. Please try again.