Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-207 fixed missing project id for scratch3 projects #166

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter
short_name: S2CC
version: 0.10.0
build_name: Aegean cat
build_number: 1020
build_number: 1021
build_type: S2CC

;-------------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/scratchtocatrobat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,25 @@ def check_converter_environment():
progress_bar = helpers.ProgressBar(None, web_mode, sys.stdout)
with common.TemporaryDirectory(remove_on_exit=temp_rm) as scratch_project_dir:
is_local_project = True
project_id = None
if scratch_project_file_or_url.startswith("https://"):
is_local_project = False
validate_scratch_url(scratch_project_file_or_url)

project_ID = scratchwebapi.extract_project_id_from_url(scratch_project_file_or_url)
if not scratchwebapi.request_is_project_available(project_ID):
raise common.ScratchtobatError("Project with ID %s not available" % project_ID)
visibility = scratchwebapi.getMetaDataEntry(project_ID, "visibility")
project_id = scratchwebapi.extract_project_id_from_url(scratch_project_file_or_url)
if not scratchwebapi.request_is_project_available(project_id):
raise common.ScratchtobatError("Project with ID %s not available" % project_id)
visibility = scratchwebapi.getMetaDataEntry(project_id, "visibility")
if visibility != scratchwebapi.ScratchProjectVisibiltyState.PUBLIC:
log.warn('-'*80)
log.warn("CAVE: Project with ID %s is NOT a public project!! Trying to " \
"continue the conversion-process anyway, but expecting the " \
"conversion to fail or to be incomplete...", project_ID)
"conversion to fail or to be incomplete...", project_id)
log.warn('-'*80)
log.info("Downloading project from URL: '{}' to temp dir {} ...".format(
scratch_project_file_or_url, scratch_project_dir))
scratchwebapi.download_project(scratch_project_file_or_url, scratch_project_dir, progress_bar)
scratch3ProjectName = scratchwebapi.getMetaDataEntry(project_ID, "title")
scratch3ProjectName = scratchwebapi.getMetaDataEntry(project_id, "title")

elif os.path.isfile(scratch_project_file_or_url):
log.info("Extracting project from path: '{}' ...".format(scratch_project_file_or_url))
Expand All @@ -130,11 +131,10 @@ def check_converter_environment():
log.info("Loading project from path: '{}' ...".format(scratch_project_file_or_url))
scratch_project_dir = scratch_project_file_or_url


isScratch3Project = scratch3.is_scratch3_project(scratch_project_dir)

if isScratch3Project:
scratch3.convert_to_scratch2_data(scratch_project_dir)
scratch3.convert_to_scratch2_data(scratch_project_dir, project_id)

project = scratch.Project(scratch_project_dir, progress_bar=progress_bar, is_local_project = is_local_project)
if isScratch3Project:
Expand Down
5 changes: 4 additions & 1 deletion src/scratchtocatrobat/scratch/scratch3.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ def is_scratch3_project(scratch_project_dir):
else:
return False

def convert_to_scratch2_data(scratch_project_dir):
def convert_to_scratch2_data(scratch_project_dir, project_id):
parser = Scratch3Parser(os.path.join(scratch_project_dir, helpers.config.get("SCRATCH", "code_file_name")), scratch_project_dir)
scratch2Data = parser.parse_sprites()
assert "info" in scratch2Data
assert "projectID" not in scratch2Data["info"]
scratch2Data["info"]["projectID"] = project_id
with open(os.path.join(scratch_project_dir, helpers.config.get("SCRATCH", "code_file_name")), 'w') as json_file:
json_file.flush()
json.dump(scratch2Data, json_file, sort_keys=True, indent=4, separators=(',', ': '))
8 changes: 5 additions & 3 deletions src/scratchtocatrobat/scratch/test_scratchwebapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ def test_can_download_project_from_project_url(self):
result_folder_path = self._testresult_folder_path
scratchwebapi.download_project(project_url, result_folder_path)
if scratch3.is_scratch3_project(result_folder_path):
scratch3.convert_to_scratch2_data(result_folder_path)
scratch3.convert_to_scratch2_data(result_folder_path, project_id)

# TODO: replace with verifying function
assert scratch.Project(result_folder_path) is not None
project = scratch.Project(result_folder_path)
assert project is not None
assert project.project_id == project_id

def test_fail_download_project_on_wrong_url(self):
for wrong_url in ['http://www.tugraz.at', 'http://www.ist.tugraz.at/', 'http://scratch.mit.edu/', 'http://scratch.mit.edu/projects']:
Expand All @@ -286,7 +288,7 @@ def test_can_request_project_code_for_id(self):
for _project_url, project_id in common_testing.TEST_PROJECT_URL_TO_ID_MAP.iteritems():
scratchwebapi.download_project_code(project_id, temp_dir)
if scratch3.is_scratch3_project(temp_dir):
scratch3.convert_to_scratch2_data(temp_dir)
scratch3.convert_to_scratch2_data(temp_dir, project_id)
project_file_path = os.path.join(temp_dir, scratch._PROJECT_FILE_NAME)
with open(project_file_path, 'r') as project_code_file:
project_code_content = project_code_file.read()
Expand Down